我在miniconda虚拟环境中使用Python 3上的matplotlib版本2.0.0.我正在开发一个unix科学计算集群,我没有root权限.我通常通过ipython笔记本执行python代码.如果我执行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
Run Code Online (Sandbox Code Playgroud)
我收到一条错误消息:
path_to_miniconda/miniconda3/envs/conda34/lib/python3.4/site-
packages/matplotlib/font_manager.py:1297: UserWarning: findfont: Font family
['sans-serif'] not found. Falling back to DejaVu Sans
(prop.get_family(), self.defaultFamily[fontext]))
Run Code Online (Sandbox Code Playgroud)
我希望能够使用Times New Roman字体,但即使删除了我从这里找到的字体缓存文件(fontList.py3k.cache):
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
Run Code Online (Sandbox Code Playgroud)
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
Run Code Online (Sandbox Code Playgroud)
没有效果,我得到与上面相同的错误.真正的字体类型目录:
path_to_miniconda/miniconda3/ENVS/conda34/lib中/ python3.4 /站点包/ matplotlib/MPL-数据/字体/ TTF /
其中只有40种字体:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道可能会发生什么,以及如何添加其他字体?谢谢!
所以我已经尝试了几乎所有我能在 stackoverflow 上找到的东西(以及谷歌会引导我的其他任何地方);我就是不能改变该死的字体!
这是我迄今为止尝试过的非详尽清单:
按照这个问题中的建议尝试:
import matplotlib.pyplot as plt
csfont = {'fontname':'Times New Roman'}
x = [1,2,3]
y = x
plt.plot(x,y)
plt.title('Please be Times >__<',**csfont)
plt.show()
Run Code Online (Sandbox Code Playgroud)
给我这个错误日志:
>>> (executing file "<tmp 1>")
Note on using QApplication.exec_():
The GUI event loop is already running in the pyzo kernel, and exec_()
does not block. In most cases your app should run fine without the need
for modifications. For clarity, this is what the pyzo kernel does:
- Prevent deletion of …Run Code Online (Sandbox Code Playgroud)