python-2.7 - 强制 matplotlibrc 使用 Arial(字体路径)

标签 python-2.7 matplotlib seaborn

我的系统中安装了 Arial 字体:

/usr/share/fonts/truetype/msttcorefonts/Arial_Bold_Italic.ttf
/usr/share/fonts/truetype/msttcorefonts/arialbi.ttf
/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf
/usr/share/fonts/truetype/msttcorefonts/arial.ttf
/usr/share/fonts/truetype/msttcorefonts/ariali.ttf
/usr/share/fonts/truetype/msttcorefonts/arialbd.ttf
/usr/share/fonts/truetype/msttcorefonts/Arial.ttf
/usr/share/fonts/truetype/msttcorefonts/Arial_Italic.ttf
/usr/share/fonts/truetype/msttcorefonts/Arial_Black.ttf
/usr/share/xbmc/media/Fonts/arial.ttf
/usr/local/share/texmf/fonts/tfm/urw/arial
/usr/local/share/texmf/fonts/afm/urw/arial
/usr/local/share/texmf/fonts/vf/urw/arial
/usr/local/share/texmf/fonts/type1/urw/arial

我在 matplotlibrc 中进行了更改,包括以下行:
font.sans-serif      : Arial

如果我检查 IPython 内部:
import matplotlib.pyplot as plt
plt.plot([1,2,3,4,5,], '*')
t = plt.ylabel(r'1, 2, 3, 8, 9 6 11 Testing Label')
print(t.get_fontname())

输出是:
myhome/local/lib/python2.7/site-packages/matplotlib-1.4.2-py2.7-linux-
x86_64.egg/matplotlib/font_manager.py:1279: UserWarning: findfont: Font
family [u'sans-serif'] not found. Falling back to Bitstream Vera Sans
(prop.get_family(), self.defaultFamily[fontext]))

Bitstream Vera Sans

如何更改此行为并为我的所有绘图使用 Arial 字体?
为什么没有加载 Arial 字体?

有趣的是,如果我使用 Seaborn,它会返回 Liberation Sans其中第一个字体(在内部字体列表中)是 Arial,第二个是 Liberation Sans .

最佳答案

正如@BenjaminRoot 建议删除 ~/.matplotlib 上的字体缓存

事实上,在我的 Debian 系统中,virtualenv 生态系统中有 python 的东西,这样的文件夹位于 ~/.cache/matplotlib/我已经删除了所有文件和文件夹,并再次重新生成了缓存。
现在它起作用了! =]

关于python-2.7 - 强制 matplotlibrc 使用 Arial(字体路径),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28053488/

相关文章:

python - Matplotlib draw() 方法不执行任何操作

python - Pandas :将 axvspan 应用于所有子图

boxplot - 当我的数据来自 python 字典时,如何将类别名称添加到我的 seaborn 箱线图中?

python - 我可以将预训练的 pdf 函数传递给 seaborn.distplot 吗?

python - 在 seaborn 中订购箱线图 x 轴

python - py2exe 与应用程序的不同部分

python - 在 Python 3.4 中切片真的更慢吗?

python - 如何使用来自 mpl_toolkits.basemap.cm 的颜色图创建离散颜色条?

python - 获取<生成器对象<genexpr>

python - python cmd 模块中的持久历史记录