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

Skip to content

TexManager fixes. #17395

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions doc/api/api_changes_3.3/deprecations.rst
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,10 @@ This method is deprecated. Use
``SymmetricalScale.InvertedSymmetricalTransform`` are deprecated. Directly
access the transform classes from the :mod:`.scale` module.

``TexManager.cachedir``
~~~~~~~~~~~~~~~~~~~~~~~
Use `matplotlib.get_cachedir()` instead.
``TexManager.cachedir``, ``TexManager.rgba_arrayd``
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Use `matplotlib.get_cachedir()` instead for the former; there is no replacement
for the latter.

Setting `.Line2D`\'s pickradius via `.Line2D.set_picker`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
33 changes: 16 additions & 17 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ class TexManager:

# Caches.
texcache = os.path.join(mpl.get_cachedir(), 'tex.cache')
rgba_arrayd = {}
grey_arrayd = {}

font_family = 'serif'
Expand Down Expand Up @@ -85,6 +84,11 @@ class TexManager:
def cachedir(self):
return mpl.get_cachedir()

@cbook.deprecated("3.3")
@property
def rgba_arrayd(self):
return {}

@functools.lru_cache() # Always return the same instance.
def __new__(cls):
Path(cls.texcache).mkdir(parents=True, exist_ok=True)
Expand Down Expand Up @@ -369,30 +373,25 @@ def make_png(self, tex, fontsize, dpi):

def get_grey(self, tex, fontsize=None, dpi=None):
"""Return the alpha channel."""
if not fontsize:
fontsize = rcParams['font.size']
if not dpi:
dpi = rcParams['savefig.dpi']
key = tex, self.get_font_config(), fontsize, dpi
alpha = self.grey_arrayd.get(key)
if alpha is None:
pngfile = self.make_png(tex, fontsize, dpi)
X = mpl.image.imread(os.path.join(self.texcache, pngfile))
self.grey_arrayd[key] = alpha = X[:, :, -1]
rgba = mpl.image.imread(os.path.join(self.texcache, pngfile))
self.grey_arrayd[key] = alpha = rgba[:, :, -1]
return alpha

def get_rgba(self, tex, fontsize=None, dpi=None, rgb=(0, 0, 0)):
"""Return latex's rendering of the tex string as an rgba array."""
if not fontsize:
fontsize = rcParams['font.size']
if not dpi:
dpi = rcParams['savefig.dpi']
r, g, b = rgb
key = tex, self.get_font_config(), fontsize, dpi, tuple(rgb)
Z = self.rgba_arrayd.get(key)

if Z is None:
alpha = self.get_grey(tex, fontsize, dpi)
Z = np.dstack([r, g, b, alpha])
self.rgba_arrayd[key] = Z

return Z
alpha = self.get_grey(tex, fontsize, dpi)
rgba = np.empty((*alpha.shape, 4))
rgba[..., :3] = mpl.colors.to_rgb(rgb)
rgba[..., -1] = alpha
return rgba

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