我想将{Cyrillic用于matplotlib
标签,因此我发现these示例表明可以通过以下方式实现:
matplotlib.rcdefaults()
matplotlib.rcParams['font.family'] = 'fantasy'
matplotlib.rcParams['font.fantasy'] = 'Times New Roman', 'Ubuntu','Arial','Tahoma','Calibri'
当我尝试这个时,我收到以下错误:
/usr/local/lib/python2.7/dist-packages/matplotlib/font_manager.py:1279: UserWarning: findfont: Font family [u'fantasy'] not found. Falling back to Bitstream Vera Sans
(prop.get_family(), self.defaultFamily[fontext]))
我正在matplotlib
使用prettyplotlib
。
答案 0 :(得分:3)
Matpltlib无法找到字体,可能是格式错误或matplotlib/mpl-data/fonts/
文件夹下没有。尝试转换为.ttf
并使用此代码进行调试:
import matplotlib as mpl
import matplotlib.pyplot as plt
import matplotlib.font_manager as font_manager
path = '/home/username/fantasy.ttf'
prop = font_manager.FontProperties(fname=path)
mpl.rcParams['font.family'] = prop.get_name()
fig, ax = plt.subplots()
ax.set_title('Test text', fontproperties=prop, size=40)
您还可以看到可用的字体:
import matplotlib.font_manager
print matplotlib.font_manager.findSystemFonts(fontpaths=None)