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

Skip to content

Commit 1f48038

Browse files
authored
Merge pull request #17256 from anntzer/pspartialusetex
Improve ps handling of individual usetex strings.
2 parents a975e48 + 6cb9d62 commit 1f48038

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

lib/matplotlib/backends/backend_ps.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,14 @@ def draw_path_collection(self, gc, master_transform, paths, all_transforms,
469469

470470
def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
471471
# docstring inherited
472+
if not hasattr(self, "psfrag"):
473+
_log.warning(
474+
"The PS backend determines usetex status solely based on "
475+
"rcParams['text.usetex'] and does not support having "
476+
"usetex=True only for some elements; this element will thus "
477+
"be rendered as if usetex=False.")
478+
self.draw_text(gc, x, y, s, prop, angle, ismath, mtext)
479+
return
472480

473481
w, h, bl = self.get_text_width_height_descent(s, prop, ismath)
474482
fontsize = prop.get_size_in_points()

lib/matplotlib/tests/test_backend_ps.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,19 @@ def test_transparency():
117117

118118

119119
@needs_usetex
120-
def test_failing_latex(tmpdir):
120+
def test_failing_latex():
121121
"""Test failing latex subprocess call"""
122122
mpl.rcParams['text.usetex'] = True
123123
# This fails with "Double subscript"
124124
plt.xlabel("$22_2_2$")
125125
with pytest.raises(RuntimeError):
126-
plt.savefig(Path(tmpdir, "tmpoutput.ps"))
126+
plt.savefig(io.BytesIO(), format="ps")
127+
128+
129+
@needs_usetex
130+
def test_partial_usetex(caplog):
131+
caplog.set_level("WARNING")
132+
plt.figtext(.5, .5, "foo", usetex=True)
133+
plt.savefig(io.BytesIO(), format="ps")
134+
assert caplog.records and all("as if usetex=False" in record.getMessage()
135+
for record in caplog.records)

lib/matplotlib/text.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ def draw(self, renderer):
726726
if textobj.get_usetex():
727727
textrenderer.draw_tex(gc, x, y, clean_line,
728728
textobj._fontproperties, angle,
729-
mtext=mtext)
729+
ismath=ismath, mtext=mtext)
730730
else:
731731
textrenderer.draw_text(gc, x, y, clean_line,
732732
textobj._fontproperties, angle,

0 commit comments

Comments
 (0)