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

Skip to content

Commit 90b149f

Browse files
authored
Merge pull request #19795 from anntzer/untex
Remove usetex-related APIs deprecated in Matplotlib 3.3.
2 parents c81f58d + eb31723 commit 90b149f

File tree

8 files changed

+43
-265
lines changed

8 files changed

+43
-265
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
``Dvi.baseline``
2+
~~~~~~~~~~~~~~~~
3+
... is deprecated (with no replacement).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
usetex-related removals
2+
~~~~~~~~~~~~~~~~~~~~~~~
3+
4+
The ``text.latex.preview`` rcParam and associated methods
5+
(``TexManager.make_tex_preview``, ``TexManager.make_dvi_preview``) have been
6+
removed.
7+
8+
The ``cachedir``, ``rgba_arrayd``, ``serif``, ``sans_serif``, ``cursive``, and
9+
``monospace`` attributes of ``TexManager`` have been removed.
10+
11+
``dviread.Encoding`` has been removed.

examples/text_labels_and_annotations/usetex_baseline_test.py

Lines changed: 6 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -3,76 +3,24 @@
33
Usetex Baseline Test
44
====================
55
6-
A test for :rc:`text.latex.preview`, a deprecated feature which relied
7-
on the preview.sty LaTeX package to properly align TeX baselines. This
8-
feature has been deprecated as Matplotlib's dvi parser now computes baselines
9-
just as well as preview.sty; this example will be removed together with
10-
:rc:`text.latex.preview` after the deprecation elapses.
6+
Comparison of text baselines computed for mathtext and usetex.
117
"""
128

139
import matplotlib.pyplot as plt
14-
import matplotlib.axes as maxes
1510

1611

1712
plt.rcParams.update({"mathtext.fontset": "cm", "mathtext.rm": "serif"})
18-
19-
20-
@maxes.subplot_class_factory
21-
class LatexPreviewSubplot(maxes.Axes):
22-
"""
23-
A hackish way to simultaneously draw texts with text.latex.preview=True and
24-
text.latex.preview=False in the same figure. It does not work with the ps
25-
backend.
26-
"""
27-
28-
def __init__(self, *args, preview=False, **kwargs):
29-
self.preview = preview
30-
super().__init__(*args, **kwargs)
31-
32-
def draw(self, renderer):
33-
from matplotlib import _api # internal, *do not use*
34-
with _api.suppress_matplotlib_deprecation_warning():
35-
with plt.rc_context({"text.latex.preview": self.preview}):
36-
super().draw(renderer)
37-
38-
39-
def test_window_extent(ax, usetex, preview):
40-
41-
ax.xaxis.set_visible(False)
42-
ax.yaxis.set_visible(False)
43-
44-
test_strings = ["lg", r"$\frac{1}{2}\pi$",
45-
r"$p^{3^A}$", r"$p_{3_2}$"]
46-
13+
axs = plt.figure(figsize=(2 * 3, 6.5)).subplots(1, 2)
14+
for ax, usetex in zip(axs, [False, True]):
4715
ax.axvline(0, color="r")
48-
16+
test_strings = ["lg", r"$\frac{1}{2}\pi$", r"$p^{3^A}$", r"$p_{3_2}$"]
4917
for i, s in enumerate(test_strings):
5018
ax.axhline(i, color="r")
5119
ax.text(0., 3 - i, s,
5220
usetex=usetex,
5321
verticalalignment="baseline",
5422
size=50,
5523
bbox=dict(pad=0, ec="k", fc="none"))
56-
57-
ax.set_xlim(-0.1, 1.1)
58-
ax.set_ylim(-.8, 3.9)
59-
60-
title = f"usetex={usetex}\n"
61-
if usetex:
62-
title += f"preview={preview}"
63-
ax.set_title(title)
64-
65-
66-
fig = plt.figure(figsize=(2 * 3, 6.5))
67-
68-
for i, usetex, preview in [[0, False, False],
69-
[1, True, False],
70-
[2, True, True]]:
71-
ax = LatexPreviewSubplot(fig, 1, 3, i + 1, preview=preview)
72-
fig.add_subplot(ax)
73-
fig.subplots_adjust(top=0.85)
74-
75-
test_window_extent(ax, usetex=usetex, preview=preview)
76-
77-
24+
ax.set(xlim=(-0.1, 1.1), ylim=(-.8, 3.9), xticks=[], yticks=[],
25+
title=f"usetex={usetex}\n")
7826
plt.show()

lib/matplotlib/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,6 @@ def gen_candidates():
553553
'animation.avconv_args': ('3.3',),
554554
'animation.html_args': ('3.3',),
555555
'savefig.jpeg_quality': ('3.3',),
556-
'text.latex.preview': ('3.3',),
557556
}
558557

559558

lib/matplotlib/backends/backend_ps.py

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -570,19 +570,11 @@ def draw_tex(self, gc, x, y, s, prop, angle, ismath='TeX!', mtext=None):
570570
s = fontcmd % s
571571
tex = r'\color[rgb]{%s} %s' % (color, s)
572572

573-
corr = 0 # w/2*(fontsize-10)/10
574-
if dict.__getitem__(mpl.rcParams, 'text.latex.preview'):
575-
# use baseline alignment!
576-
pos = _nums_to_str(x-corr, y)
577-
self.psfrag.append(
578-
r'\psfrag{%s}[Bl][Bl][1][%f]{\fontsize{%f}{%f}%s}' % (
579-
thetext, angle, fontsize, fontsize*1.25, tex))
580-
else:
581-
# Stick to the bottom alignment.
582-
pos = _nums_to_str(x-corr, y-bl)
583-
self.psfrag.append(
584-
r'\psfrag{%s}[bl][bl][1][%f]{\fontsize{%f}{%f}%s}' % (
585-
thetext, angle, fontsize, fontsize*1.25, tex))
573+
# Stick to the bottom alignment.
574+
pos = _nums_to_str(x, y-bl)
575+
self.psfrag.append(
576+
r'\psfrag{%s}[bl][bl][1][%f]{\fontsize{%f}{%f}%s}' % (
577+
thetext, angle, fontsize, fontsize*1.25, tex))
586578

587579
self._pswriter.write(f"""\
588580
gsave

lib/matplotlib/dviread.py

Lines changed: 4 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
import numpy as np
3232

33-
from matplotlib import _api, cbook, rcParams
33+
from matplotlib import _api, cbook
3434

3535
_log = logging.getLogger(__name__)
3636

@@ -212,15 +212,8 @@ def __init__(self, filename, dpi):
212212
self.dpi = dpi
213213
self.fonts = {}
214214
self.state = _dvistate.pre
215-
self.baseline = self._get_baseline(filename)
216-
217-
def _get_baseline(self, filename):
218-
if dict.__getitem__(rcParams, 'text.latex.preview'):
219-
baseline = Path(filename).with_suffix(".baseline")
220-
if baseline.exists():
221-
height, depth, width = baseline.read_bytes().split()
222-
return float(depth)
223-
return None
215+
216+
baseline = _api.deprecated("3.5")(property(lambda self: None))
224217

225218
def __enter__(self):
226219
"""Context manager enter method, does nothing."""
@@ -290,10 +283,7 @@ def _output(self):
290283

291284
# convert from TeX's "scaled points" to dpi units
292285
d = self.dpi / (72.27 * 2**16)
293-
if self.baseline is None:
294-
descent = (maxy - maxy_pure) * d
295-
else:
296-
descent = self.baseline
286+
descent = (maxy - maxy_pure) * d
297287

298288
text = [Text((x-minx)*d, (maxy-y)*d - descent, f, g, w*d)
299289
for (x, y, f, g, w) in self.text]
@@ -960,55 +950,6 @@ def _parse(self, file):
960950
encoding=encoding, filename=filename)
961951

962952

963-
@_api.deprecated("3.3")
964-
class Encoding:
965-
r"""
966-
Parse a \*.enc file referenced from a psfonts.map style file.
967-
968-
The format this class understands is a very limited subset of PostScript.
969-
970-
Usage (subject to change)::
971-
972-
for name in Encoding(filename):
973-
whatever(name)
974-
975-
Parameters
976-
----------
977-
filename : str or path-like
978-
979-
Attributes
980-
----------
981-
encoding : list
982-
List of character names
983-
"""
984-
__slots__ = ('encoding',)
985-
986-
def __init__(self, filename):
987-
with open(filename, 'rb') as file:
988-
_log.debug('Parsing TeX encoding %s', filename)
989-
self.encoding = self._parse(file)
990-
_log.debug('Result: %s', self.encoding)
991-
992-
def __iter__(self):
993-
yield from self.encoding
994-
995-
@staticmethod
996-
def _parse(file):
997-
lines = (line.split(b'%', 1)[0].strip() for line in file)
998-
data = b''.join(lines)
999-
beginning = data.find(b'[')
1000-
if beginning < 0:
1001-
raise ValueError("Cannot locate beginning of encoding in {}"
1002-
.format(file))
1003-
data = data[beginning:]
1004-
end = data.find(b']')
1005-
if end < 0:
1006-
raise ValueError("Cannot locate end of encoding in {}"
1007-
.format(file))
1008-
data = data[:end]
1009-
return re.findall(br'/([^][{}<>\s]+)', data)
1010-
1011-
1012953
# Note: this function should ultimately replace the Encoding class, which
1013954
# appears to be mostly broken: because it uses b''.join(), there is no
1014955
# whitespace left between glyph names (only slashes) so the final re.findall

lib/matplotlib/rcsetup.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,6 @@ def _convert_validator_spec(key, conv):
10861086
"text.color": validate_color,
10871087
"text.usetex": validate_bool,
10881088
"text.latex.preamble": _validate_tex_preamble,
1089-
"text.latex.preview": validate_bool,
10901089
"text.hinting": _validate_hinting,
10911090
"text.hinting_factor": validate_int,
10921091
"text.kerning_factor": validate_int,
@@ -1422,7 +1421,6 @@ def _convert_validator_spec(key, conv):
14221421
"animation.avconv_args": [],
14231422
"animation.html_args": [],
14241423
"savefig.jpeg_quality": 95,
1425-
"text.latex.preview": False,
14261424
}
14271425
_validators = {k: _convert_validator_spec(k, conv)
14281426
for k, conv in _validators.items()}

0 commit comments

Comments
 (0)