File tree Expand file tree Collapse file tree 4 files changed +13
-8
lines changed
examples/text_labels_and_annotations Expand file tree Collapse file tree 4 files changed +13
-8
lines changed Original file line number Diff line number Diff line change
1
+ The *fname * argument to `FontProperties ` can now be an `os.PathLike `\s
2
+ ``````````````````````````````````````````````````````````````````````
3
+
4
+ e.g. ``FontProperties(fname=pathlib.Path("/path/to/font.ttf")) ``.
Original file line number Diff line number Diff line change 15
15
:doc:`/gallery/text_labels_and_annotations/fonts_demo`.
16
16
"""
17
17
18
- import os
19
- from matplotlib import font_manager as fm , rcParams
18
+ from pathlib import Path
19
+
20
+ import matplotlib as mpl
21
+ from matplotlib import font_manager as fm
20
22
import matplotlib .pyplot as plt
21
23
22
24
fig , ax = plt .subplots ()
23
25
24
- fpath = os . path . join ( rcParams [ "datapath" ] , "fonts/ttf/cmr10.ttf" )
26
+ fpath = Path ( mpl . get_data_path () , "fonts/ttf/cmr10.ttf" )
25
27
prop = fm .FontProperties (fname = fpath )
26
- fname = os .path .split (fpath )[1 ]
27
- ax .set_title ('This is a special font: {}' .format (fname ), fontproperties = prop )
28
+ ax .set_title (f'This is a special font: { fpath .name } ' , fontproperties = prop )
28
29
ax .set_xlabel ('This is the default font' )
29
30
30
31
plt .show ()
Original file line number Diff line number Diff line change 13
13
14
14
It is pretty easy to use, and requires only built-in python libs:
15
15
16
- >>> from matplotlib import rcParams
16
+ >>> import matplotlib as mpl
17
17
>>> import os.path
18
- >>> afm_fname = os.path.join(rcParams['datapath'] ,
18
+ >>> afm_fname = os.path.join(mpl.get_data_path() ,
19
19
... 'fonts', 'afm', 'ptmr8a.afm')
20
20
>>>
21
21
>>> from matplotlib.afm import AFM
Original file line number Diff line number Diff line change @@ -1275,7 +1275,7 @@ def is_opentype_cff_font(filename):
1275
1275
def get_font (filename , hinting_factor = None ):
1276
1276
if hinting_factor is None :
1277
1277
hinting_factor = rcParams ['text.hinting_factor' ]
1278
- return _get_font (filename , hinting_factor )
1278
+ return _get_font (os . fspath ( filename ) , hinting_factor )
1279
1279
1280
1280
1281
1281
def _rebuild ():
You can’t perform that action at this time.
0 commit comments