Find out which font matplotlib uses

后端 未结 1 1541
春和景丽
春和景丽 2020-12-15 08:10

Im looking for a nice way to get the name of the default font that is used by matplotlib.pyplot. The documentation indicates that the font is selected from the list in rcPar

1条回答
  •  有刺的猬
    2020-12-15 08:35

    To obtain the font family:

    matplotlib.rcParams['font.family']
    

    If it's a general font family like 'sans-serif', use fontfind to find the actual font:

    >>> from matplotlib.font_manager import findfont, FontProperties
    >>> font = findfont(FontProperties(family=['sans-serif']))
    >>> font
    '/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/matplotlib/mpl-data/fonts/ttf/Vera.ttf'
    

    I found this in the unit tests of the font_manager: https://github.com/matplotlib/matplotlib/blob/4314d447dfc7127daa80fa295c9bd56cf07faf01/lib/matplotlib/tests/test_font_manager.py

    0 讨论(0)
提交回复
热议问题