Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 23dad88

Browse files
committed
Deprecate \mathcircled.
It is not a real TeX command and requires workarounds in the build. One can directly use the corresponding unicode characters instead (for which \mathcircled is basically a Matplotlib-only shorthand).
1 parent 3b5f672 commit 23dad88

File tree

5 files changed

+41
-14
lines changed

5 files changed

+41
-14
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Deprecations
2+
````````````
3+
4+
The `\mathcircled` mathtext command (which is not a real TeX command)
5+
is deprecated. Directly use unicode characters (e.g.
6+
``"\N{CIRCLED LATIN CAPITAL LETTER A}"`` or ``"\u24b6"``) instead.
7+
8+
Support for setting :rc:`mathtext.default` to circled is deprecated.

examples/text_labels_and_annotations/stix_fonts_demo.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@
88
import matplotlib.pyplot as plt
99
import numpy as np
1010

11+
12+
circle123 = "\N{CIRCLED DIGIT ONE}\N{CIRCLED DIGIT TWO}\N{CIRCLED DIGIT THREE}"
13+
1114
tests = [
12-
r'$\mathcircled{123} \mathrm{\mathcircled{123}}'
13-
r' \mathbf{\mathcircled{123}}$',
15+
r'$%s \mathrm{%s} \mathbf{%s}$' % ((circle123,) * 3),
1416
r'$\mathsf{Sans \Omega} \mathrm{\mathsf{Sans \Omega}}'
1517
r' \mathbf{\mathsf{Sans \Omega}}$',
1618
r'$\mathtt{Monospace}$',
@@ -19,14 +21,12 @@
1921
r'$\mathrm{\mathbb{Blackboard \pi}}$',
2022
r'$\mathbf{\mathbb{Blackboard \pi}}$',
2123
r'$\mathfrak{Fraktur} \mathbf{\mathfrak{Fraktur}}$',
22-
r'$\mathscr{Script}$']
24+
r'$\mathscr{Script}$',
25+
]
2326

2427

25-
plt.figure(figsize=(8, (len(tests) * 1) + 2))
26-
plt.plot([0, 0], 'r')
27-
plt.axis([0, 3, -len(tests), 0])
28-
plt.yticks(-np.arange(len(tests)))
29-
for i, s in enumerate(tests):
30-
plt.text(0.1, -i, s, fontsize=32)
28+
fig = plt.figure(figsize=(8, (len(tests) * 1) + 2))
29+
for i, s in enumerate(tests[::-1]):
30+
fig.text(0, (i + .5) / len(tests), s, fontsize=32)
3131

3232
plt.show()

lib/matplotlib/mathtext.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2638,6 +2638,11 @@ def font(self):
26382638

26392639
@font.setter
26402640
def font(self, name):
2641+
if name == "circled":
2642+
cbook.warn_deprecated(
2643+
"3.1", name="\\mathcircled", obj_type="mathtext command",
2644+
alternative="unicode characters (e.g. '\\N{CIRCLED LATIN "
2645+
"CAPITAL LETTER A}' or '\\u24b6')")
26412646
if name in ('rm', 'it', 'bf'):
26422647
self.font_class = name
26432648
self._font = name

lib/matplotlib/rcsetup.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,19 @@ def validate_font_properties(s):
469469
validate_fontset = ValidateInStrings(
470470
'fontset',
471471
['dejavusans', 'dejavuserif', 'cm', 'stix', 'stixsans', 'custom'])
472-
validate_mathtext_default = ValidateInStrings(
473-
'default',
474-
"rm cal it tt sf bf default bb frak circled scr regular".split())
472+
473+
474+
def validate_mathtext_default(s):
475+
if s == "circled":
476+
cbook.warn_deprecated(
477+
"3.1", message="Support for setting the mathtext.default rcParam "
478+
"to 'circled' is deprecated since %(since)s and will be removed "
479+
"%(removal)s.")
480+
return ValidateInStrings(
481+
'default',
482+
"rm cal it tt sf bf default bb frak circled scr regular".split())(s)
483+
484+
475485
_validate_alignment = ValidateInStrings(
476486
'alignment',
477487
['center', 'top', 'bottom', 'baseline',

lib/matplotlib/tests/test_mathtext.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,18 @@ def baseline_images(request, fontset, index):
163163
return ['%s_%s_%02d' % (request.param, fontset, index)]
164164

165165

166+
# In the following two tests, use recwarn to suppress warnings regarding the
167+
# deprecation of \stackrel and \mathcircled.
168+
169+
166170
@pytest.mark.parametrize('index, test', enumerate(math_tests),
167171
ids=[str(index) for index in range(len(math_tests))])
168172
@pytest.mark.parametrize('fontset',
169173
['cm', 'stix', 'stixsans', 'dejavusans',
170174
'dejavuserif'])
171175
@pytest.mark.parametrize('baseline_images', ['mathtext'], indirect=True)
172176
@image_comparison(baseline_images=None)
173-
def test_mathtext_rendering(baseline_images, fontset, index, test):
177+
def test_mathtext_rendering(baseline_images, fontset, index, test, recwarn):
174178
matplotlib.rcParams['mathtext.fontset'] = fontset
175179
fig = plt.figure(figsize=(5.25, 0.75))
176180
fig.text(0.5, 0.5, test,
@@ -184,7 +188,7 @@ def test_mathtext_rendering(baseline_images, fontset, index, test):
184188
'dejavuserif'])
185189
@pytest.mark.parametrize('baseline_images', ['mathfont'], indirect=True)
186190
@image_comparison(baseline_images=None, extensions=['png'])
187-
def test_mathfont_rendering(baseline_images, fontset, index, test):
191+
def test_mathfont_rendering(baseline_images, fontset, index, test, recwarn):
188192
matplotlib.rcParams['mathtext.fontset'] = fontset
189193
fig = plt.figure(figsize=(5.25, 0.75))
190194
fig.text(0.5, 0.5, test,

0 commit comments

Comments
 (0)