8000 Text.{get,set}_usetex: manually enable/disable TeX · matplotlib/matplotlib@6b03c54 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6b03c54

Browse files
Text.{get,set}_usetex: manually enable/disable TeX
- defaults to rcParams['text.usetex'] - useful for, e.g, timestamps for Animations on machines with slow TeX rendering
1 parent f83bfd3 commit 6b03c54

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

lib/matplotlib/text.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def get_rotation(rotation):
9999
style or fontstyle [ 'normal' | 'italic' | 'oblique']
100100
text string
101101
transform a matplotlib.transform transformation instance
102+
usetex [True | False | None]
102103
variant ['normal' | 'small-caps']
103104
verticalalignment or va ['center' | 'top' | 'bottom' | 'baseline']
104105
visible [True | False]
@@ -173,6 +174,7 @@ def __init__(self,
173174
rotation=None,
174175
linespacing=None,
175176
rotation_mode=None,
177+
usetex=None, # defaults to rcParams['text.usetex']
176178
**kwargs
177179
):
178180
"""
@@ -195,6 +197,7 @@ def __init__(self,
195197

196198
self.set_text(text)
197199
self.set_color(color)
200+
self.set_usetex(usetex)
198201
self._verticalalignment = verticalalignment
199202
self._horizontalalignment = horizontalalignment
200203
self._multialignment = multialignment
@@ -582,7 +585,7 @@ def draw(self, renderer):
582585
renderer = PathEffectRenderer(self.get_path_effects(),
583586
renderer)
584587

585-
if rcParams['text.usetex']:
588+
if self.get_usetex():
586589
renderer.draw_tex(gc, x, y, clean_line,
587590
self._fontproperties, angle, mtext=mtext)
588591
else:
@@ -1010,6 +1013,30 @@ def set_font_properties(self, fp):
10101013
'alias for set_fontproperties'
10111014
self.set_fontproperties(fp)
10121015

1016+
def set_usetex(self, usetex):
1017+
"""
1018+
Set this `Text` object to render using TeX (or not).
1019+
1020+
If `None` is given, the option will be reset to use the value of
1021+
`rcParams['text.usetex']`
1022+
"""
1023+
if usetex is None:
1024+
self._usetex = None
1025+
else:
1026+
self._usetex = bool(usetex)
1027+
1028+
def get_usetex(self):
1029+
"""
1030+
Return whether this `Text` object will render using TeX.
1031+
1032+
If the user has not manually set this value, it will default to
1033+
the value of `rcParams['text.usetex']`
1034+
"""
1035+
if self._usetex is None:
1036+
return rcParams['text.usetex']
1037+
else:
1038+
return self._usetex
1039+
10131040
docstring.interpd.update(Text=artist.kwdoc(Text))
10141041
docstring.dedent_interpd(Text.__init__)
10151042

0 commit comments

Comments
 (0)
0