【发布时间】:2014-02-14 19:08:45
【问题描述】:
这听起来是一个简单的问题,但我没有找到任何有效的解决方案来更改在 python 中使用 matplotlib 制作的绘图中的字体(不是字体大小)。
我找到了几个教程,通过修改 matplotlib 存储其默认字体的文件夹中的一些文件来更改 matplotlib 的默认字体 - 请参阅 this blog post - 但我正在寻找一个不太激进的解决方案,因为我想使用我的绘图中不止一种字体(文本、标签、轴标签等)。
【问题讨论】:
-
很高兴它有帮助:) 你能发布导致这个错误的代码吗?我自己没有看到这个错误,但这里有一些可能对你有帮助的链接。 matplotlib.1069221.n5.nabble.com/…matplotlib.1069221.n5.nabble.com/Fonts-not-found-td12936.html
-
产生问题的代码是:
hfont = {'fontname':'Helvetica'} plt.annotate('Country ', (0.17,0.95), xytext=None, xycoords='figure fraction',size=28, color='red', horizontalalignment = 'left', **hfont),错误是/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/matplotlib/font_manager.py:1236: UserWarning: findfont: Font family ['Helvetica'] not found. Falling back to Bitstream Vera Sans (prop.get_family(), self.defaultFamily[fontext])),如果我在你的例子中使用Comic Sans MS作为字体名,代码可以工作。
标签: python fonts matplotlib