强制 matplotlibrc 使用 Arial(字体路径) [英] Force matplotlibrc to use Arial (path of font)
问题描述
我的系统中安装了Arial字体:
I have Arial font installed in my system:
/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内部进行了更改,包括以下行:
I have changed inside my matplotlibrc including the line:
font.sans-serif : Arial
如果我在IPython内部检查:
If I check inside 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字体?
How can I change this behavior and use Arial fonts for all of my plots? Why Arial font is not loaded?
有趣的是,如果我使用 Seaborn,它会返回 Liberation Sans
,其中第一个字体(在内部字体列表中)是 Arial,第二个是 Liberation Sans
.
It is interesting, that if I use Seaborn, it returns Liberation Sans
where the first font (inside internal font list) is Arial and the second is Liberation Sans
.
推荐答案
@BenjaminRoot建议删除〜/.matplotlib
As suggested by @BenjaminRoot to delete the font cache on ~/.matplotlib
事实上,在我的 Debian 系统中,virtualenv 生态系统中有 python 的东西,这样的文件夹位于 ~/.cache/matplotlib/
我已经删除了所有文件和文件夹,并且再次重新生成了缓存.现在它起作用了!=]
In fact in my Debian system, with python stuff inside virtualenv ecosystem, such folder was located at ~/.cache/matplotlib/
I have deleted all files and folder and the cache was regenerated again.
Now it works! =]
这篇关于强制 matplotlibrc 使用 Arial(字体路径)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!