@@ -53,7 +53,6 @@ class TexManager:
53
53
54
54
# Caches.
55
55
texcache = os .path .join (mpl .get_cachedir (), 'tex.cache' )
56
- rgba_arrayd = {}
57
56
grey_arrayd = {}
58
57
59
58
font_family = 'serif'
@@ -85,6 +84,11 @@ class TexManager:
85
84
def cachedir (self ):
86
85
return mpl .get_cachedir ()
87
86
87
+ @cbook .deprecated ("3.3" )
88
+ @property
89
+ def rgba_arrayd (self ):
90
+ return {}
91
+
88
92
@functools .lru_cache () # Always return the same instance.
89
93
def __new__ (cls ):
90
94
Path (cls .texcache ).mkdir (parents = True , exist_ok = True )
@@ -369,30 +373,25 @@ def make_png(self, tex, fontsize, dpi):
369
373
370
374
def get_grey (self , tex , fontsize = None , dpi = None ):
371
375
"""Return the alpha channel."""
376
+ if not fontsize :
377
+ fontsize = rcParams ['font.size' ]
378
+ if not dpi :
379
+ dpi = rcParams ['savefig.dpi' ]
372
380
key = tex , self .get_font_config (), fontsize , dpi
373
381
alpha = self .grey_arrayd .get (key )
374
382
if alpha is None :
375
383
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 ]
378
386
return alpha
379
387
380
388
def get_rgba (self , tex , fontsize = None , dpi = None , rgb = (0 , 0 , 0 )):
381
389
"""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
396
395
397
396
def get_text_width_height_descent (self , tex , fontsize , renderer = None ):
398
397
"""Return width, height and descent of the text."""
0 commit comments