[英]Matplotlib reports font family 'serif' not found
当我尝试运行时,例如:
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
文件的字体系列相关部分
卸载并重新安装matplotlib
使用pip uninstall matplotlib
和pip install matplotlib
什么都没有解决这个问题。 我现在获得不同字体的唯一可能方法是使用 LaTeX 作为后端,但这很慢而且没有必要。
任何想法我接下来可以尝试什么?
编辑:我使用的是 Windows 10,所以没有为我使用apt-get
。 这似乎是解决这些问题的常见方法,但我做不到。 看来这些解决方案只是将 Microsoft 字体添加到 Linux 字体管理器中,因此它甚至可能无关紧要,因为我已经在使用 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 被列为可用字体。
我遇到过同样的问题。 对我来说,将我的 matplotlib 版本从回1.5.3
解决了这个问题。 您需要先pip uninstall matplotlib
然后pip install matplotlib==1.5.3
。
更多上下文,我在带有 Amazon EC2 的 zeppelin notebook 上使用ggplot
。 不知何故,安装的 matplotlib 版本是2.2.3
。
更改版本后,错误消失
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.