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

Appearance settings

Commit 6fd7d33

Browse filesBrowse files
authored
Merge pull request #20278 from anntzer/tma
Deprecate public access to certain texmanager attributes.
2 parents ecba512 + af227ab commit 6fd7d33
Copy full SHA for 6fd7d33

File tree

Expand file treeCollapse file tree

2 files changed

+30
-22
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+30
-22
lines changed
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
``TexManager`` attributes
2+
~~~~~~~~~~~~~~~~~~~~~~~~~
3+
The following attributes of `.TexManager` are deprecated: ``grey_arrayd``,
4+
``font_family``, ``font_families``, ``font_info``.

‎lib/matplotlib/texmanager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/texmanager.py
+26-22Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import numpy as np
3232

3333
import matplotlib as mpl
34-
from matplotlib import cbook, dviread, rcParams
34+
from matplotlib import _api, cbook, dviread, rcParams
3535

3636
_log = logging.getLogger(__name__)
3737

@@ -43,14 +43,12 @@ class TexManager:
4343
Repeated calls to this constructor always return the same instance.
4444
"""
4545

46-
# Caches.
4746
texcache = os.path.join(mpl.get_cachedir(), 'tex.cache')
48-
grey_arrayd = {}
4947

50-
font_family = 'serif'
51-
font_families = ('serif', 'sans-serif', 'cursive', 'monospace')
52-
53-
font_info = {
48+
_grey_arrayd = {}
49+
_font_family = 'serif'
50+
_font_families = ('serif', 'sans-serif', 'cursive', 'monospace')
51+
_font_info = {
5452
'new century schoolbook': ('pnc', r'\renewcommand{\rmdefault}{pnc}'),
5553
'bookman': ('pbk', r'\renewcommand{\rmdefault}{pbk}'),
5654
'times': ('ptm', r'\usepackage{mathptmx}'),
@@ -71,36 +69,42 @@ class TexManager:
7169
'computer modern sans serif': ('cmss', r'\usepackage{type1ec}'),
7270
'computer modern typewriter': ('cmtt', r'\usepackage{type1ec}')}
7371

72+
grey_arrayd = _api.deprecate_privatize_attribute("3.5")
73+
font_family = _api.deprecate_privatize_attribute("3.5")
74+
font_families = _api.deprecate_privatize_attribute("3.5")
75+
font_info = _api.deprecate_privatize_attribute("3.5")
76+
7477
@functools.lru_cache() # Always return the same instance.
7578
def __new__(cls):
7679
Path(cls.texcache).mkdir(parents=True, exist_ok=True)
7780
return object.__new__(cls)
7881

7982
def get_font_config(self):
8083
ff = rcParams['font.family']
81-
if len(ff) == 1 and ff[0].lower() in self.font_families:
82-
self.font_family = ff[0].lower()
84+
if len(ff) == 1 and ff[0].lower() in self._font_families:
85+
self._font_family = ff[0].lower()
8386
else:
8487
_log.info('font.family must be one of (%s) when text.usetex is '
8588
'True. serif will be used by default.',
86-
', '.join(self.font_families))
87-
self.font_family = 'serif'
89+
', '.join(self._font_families))
90+
self._font_family = 'serif'
8891

89-
fontconfig = [self.font_family]
92+
fontconfig = [self._font_family]
9093
fonts = {}
91-
for font_family in self.font_families:
94+
for font_family in self._font_families:
9295
for font in rcParams['font.' + font_family]:
93-
if font.lower() in self.font_info:
94-
fonts[font_family] = self.font_info[font.lower()]
95-
_log.debug('family: %s, font: %s, info: %s',
96-
font_family, font, self.font_info[font.lower()])
96+
if font.lower() in self._font_info:
97+
fonts[font_family] = self._font_info[font.lower()]
98+
_log.debug(
99+
'family: %s, font: %s, info: %s',
100+
font_family, font, self._font_info[font.lower()])
97101
break
98102
else:
99103
_log.debug('%s font is not compatible with usetex.', font)
100104
else:
101105
_log.info('No LaTeX-compatible font found for the %s font '
102106
'family in rcParams. Using default.', font_family)
103-
fonts[font_family] = self.font_info[font_family]
107+
fonts[font_family] = self._font_info[font_family]
104108
fontconfig.append(fonts[font_family][0])
105109
# Add a hash of the latex preamble to fontconfig so that the
106110
# correct png is selected for strings rendered with same font and dpi
@@ -112,7 +116,7 @@ def get_font_config(self):
112116
# file's preamble:
113117
cmd = {fonts[family][1]
114118
for family in ['serif', 'sans-serif', 'monospace']}
115-
if self.font_family == 'cursive':
119+
if self._font_family == 'cursive':
116120
cmd.add(fonts['cursive'][1])
117121
cmd.add(r'\usepackage{type1cm}')
118122
self._font_preamble = '\n'.join(sorted(cmd))
@@ -169,7 +173,7 @@ def make_tex(self, tex, fontsize):
169173
basefile = self.get_basefile(tex, fontsize)
170174
texfile = '%s.tex' % basefile
171175
fontcmd = {'sans-serif': r'{\sffamily %s}',
172-
'monospace': r'{\ttfamily %s}'}.get(self.font_family,
176+
'monospace': r'{\ttfamily %s}'}.get(self._font_family,
173177
r'{\rmfamily %s}')
174178

175179
Path(texfile).write_text(
@@ -262,11 +266,11 @@ def get_grey(self, tex, fontsize=None, dpi=None):
262266
if not dpi:
263267
dpi = rcParams['savefig.dpi']
264268
key = tex, self.get_font_config(), fontsize, dpi
265-
alpha = self.grey_arrayd.get(key)
269+
alpha = self._grey_arrayd.get(key)
266270
if alpha is None:
267271
pngfile = self.make_png(tex, fontsize, dpi)
268272
rgba = mpl.image.imread(os.path.join(self.texcache, pngfile))
269-
self.grey_arrayd[key] = alpha = rgba[:, :, -1]
273+
self._grey_arrayd[key] = alpha = rgba[:, :, -1]
270274
return alpha
271275

272276
def get_rgba(self, tex, fontsize=None, dpi=None, rgb=(0, 0, 0)):

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.