3131import numpy as np
3232
3333import 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