Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdd3b02c

Browse files
authored
Merge pull request#22556 from oscargus/parse_math_rcparams
Add text.parse_math rcParams
2 parents2e921df +2023a54 commitdd3b02c

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

‎lib/matplotlib/mpl-data/matplotlibrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@
301301
# Values other than 0 or 6 have no defined meaning.
302302
#text.antialiased: True # If True (default), the text will be antialiased.
303303
# This only affects raster outputs.
304+
#text.parse_math: True # Use mathtext if there is an even number of unescaped
305+
# dollar signs.
304306

305307

306308
## ***************************************************************************

‎lib/matplotlib/rcsetup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,7 @@ def _convert_validator_spec(key, conv):
932932
"text.hinting_factor":validate_int,
933933
"text.kerning_factor":validate_int,
934934
"text.antialiased":validate_bool,
935+
"text.parse_math":validate_bool,
935936

936937
"mathtext.cal":validate_font_properties,
937938
"mathtext.rm":validate_font_properties,

‎lib/matplotlib/tests/test_text.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,20 @@ def test_parse_math():
755755
fig.canvas.draw()
756756

757757

758+
deftest_parse_math_rcparams():
759+
# Default is True
760+
fig,ax=plt.subplots()
761+
ax.text(0,0,r"$ \wrong{math} $")
762+
withpytest.raises(ValueError,match='Unknown symbol'):
763+
fig.canvas.draw()
764+
765+
# Setting rcParams to False
766+
withmpl.rc_context({'text.parse_math':False}):
767+
fig,ax=plt.subplots()
768+
ax.text(0,0,r"$ \wrong{math} $")
769+
fig.canvas.draw()
770+
771+
758772
@image_comparison(['text_pdf_font42_kerning.pdf'],style='mpl20')
759773
deftest_pdf_font42_kerning():
760774
plt.rcParams['pdf.fonttype']=42

‎lib/matplotlib/text.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ def __init__(self,
142142
wrap=False,
143143
transform_rotates_text=False,
144144
*,
145-
parse_math=True,
145+
parse_math=None,# defaults to rcParams['text.parse_math']
146146
**kwargs
147147
):
148148
"""
@@ -163,7 +163,8 @@ def __init__(self,
163163
colorifcolorisnotNoneelsempl.rcParams["text.color"])
164164
self.set_fontproperties(fontproperties)
165165
self.set_usetex(usetex)
166-
self.set_parse_math(parse_math)
166+
self.set_parse_math(parse_mathifparse_mathisnotNoneelse
167+
mpl.rcParams['text.parse_math'])
167168
self.set_wrap(wrap)
168169
self.set_verticalalignment(verticalalignment)
169170
self.set_horizontalalignment(horizontalalignment)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp