当我尝试运行,例如:
在Jupyter笔记本中,我收到以下错误消息:
在
mpl.rcParams['font.family'] = 'serif'
plt.rcParams['figure.figsize'] = [15,7]
plt.plot(data['flow-time'], data['staticpressurerecovery'])
plt.xlabel('Time [s]')
plt.ylabel('Static Pressure Recovery [-]')
plt.title('McD13_4S3 Plenum: Performance Coefficient ')
plt.ylim((0.33, 0.4))
plt.grid()
plt.show()
在Jupyter笔记本中,我收到以下错误消息:
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\font_manager.py:1331: UserWarning: findfont: Font family ['serif'] not found. Falling back to DejaVu Sans
(prop.get_family(), self.defaultFamily[fontext]))
我尝试过的事情:
删除
fontList.cache
、fontList.json
和fontList.py3.cache
取消注释
matplotlibrc
文件中与字体家族相关的部分使用
pip uninstall matplotlib
和pip install matplotlib
卸载和重新安装matplotlib
没有解决这个问题。现在,我唯一可能得到不同字体的方法是使用LaTeX作为后端,但那很慢,也没必要。
有什么想法可以尝试吗?
编辑:我使用的是Windows 10,所以不能使用apt-get
。那似乎是这些问题的常见解决方案,但我做不到。它似乎只是向Linux字体管理器添加Microsoft字体,因此对我来说可能并不相关,因为我已经在Microsoft机器上了。
最小工作示例:
import matplotlib.pyplot as plt
import matplotlib as mpl
import numpy as np
mpl.rcParams['font.family'] = 'serif'
mpl.rcParams['font.serif'] = 'Computer Modern'
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2*np.pi*t)
plt.plot(t, s)
plt.show()
在
fontList.json
中,Computer Modern 被列为可用字体。
mathtext.fontset
的有效字体集,但是我的Windows电脑上并没有安装Computer Modern作为TTF字体。类似于mpl.rcParams ['font.serif'] ='Times New Roman'
这样的设置在任何Windows计算机上都可以使用。 - ImportanceOfBeingErnest