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

Skip to content

Commit 8bddf0a

Browse files
authored
Merge pull request #17395 from anntzer/texman
TexManager fixes.
2 parents f4f365f + 0de8ef5 commit 8bddf0a

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

doc/api/api_changes_3.3/deprecations.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@ This method is deprecated. Use
137137
``SymmetricalScale.InvertedSymmetricalTransform`` are deprecated. Directly
138138
access the transform classes from the :mod:`.scale` module.
139139

140-
``TexManager.cachedir``
141-
~~~~~~~~~~~~~~~~~~~~~~~
142-
Use `matplotlib.get_cachedir()` instead.
140+
``TexManager.cachedir``, ``TexManager.rgba_arrayd``
141+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
142+
Use `matplotlib.get_cachedir()` instead for the former; there is no replacement
143+
for the latter.
143144

144145
Setting `.Line2D`\'s pickradius via `.Line2D.set_picker`
145146
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

lib/matplotlib/texmanager.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ class TexManager:
5353

5454
# Caches.
5555
texcache = os.path.join(mpl.get_cachedir(), 'tex.cache')
56-
rgba_arrayd = {}
5756
grey_arrayd = {}
5857

5958
font_family = 'serif'
@@ -85,6 +84,11 @@ class TexManager:
8584
def cachedir(self):
8685
return mpl.get_cachedir()
8786

87+
@cbook.deprecated("3.3")
88+
@property
89+
def rgba_arrayd(self):
90+
return {}
91+
8892
@functools.lru_cache() # Always return the same instance.
8993
def __new__(cls):
9094
Path(cls.texcache).mkdir(parents=True, exist_ok=True)
@@ -369,30 +373,25 @@ def make_png(self, tex, fontsize, dpi):
369373

370374
def get_grey(self, tex, fontsize=None, dpi=None):
371375
"""Return the alpha channel."""
376+
if not fontsize:
377+
fontsize = rcParams['font.size']
378+
if not dpi:
379+
dpi = rcParams['savefig.dpi']
372380
key = tex, self.get_font_config(), fontsize, dpi
373381
alpha = self.grey_arrayd.get(key)
374382
if alpha is None:
375383
pngfile = self.make_png(tex, fontsize, dpi)
376-
X = mpl.image.imread(os.path.join(self.texcache, pngfile))
377-
self.grey_arrayd[key] = alpha = X[:, :, -1]
384+
rgba = mpl.image.imread(os.path.join(self.texcache, pngfile))
385+
self.grey_arrayd[key] = alpha = rgba[:, :, -1]
378386
return alpha
379387

380388
def get_rgba(self, tex, fontsize=None, dpi=None, rgb=(0, 0, 0)):
381389
"""Return latex's rendering of the tex string as an rgba array."""
382-
if not fontsize:
383-
fontsize = rcParams['font.size']
384-
if not dpi:
385-
dpi = rcParams['savefig.dpi']
386-
r, g, b = rgb
387-
key = tex, self.get_font_config(), fontsize, dpi, tuple(rgb)
388-
Z = self.rgba_arrayd.get(key)
389-
390-
if Z is None:
391-
alpha = self.get_grey(tex, fontsize, dpi)
392-
Z = np.dstack([r, g, b, alpha])
393-
self.rgba_arrayd[key] = Z
394-
395-
return Z
390+
alpha = self.get_grey(tex, fontsize, dpi)
391+
rgba = np.empty((*alpha.shape, 4))
392+
rgba[..., :3] = mpl.colors.to_rgb(rgb)
393+
rgba[..., -1] = alpha
394+
return rgba
396395

397396
def get_text_width_height_descent(self, tex, fontsize, renderer=None):
398397
"""Return width, height and descent of the text."""

0 commit comments

Comments
 (0)