[英]Matplotlib reports font family 'serif' not found
When I try and run, for example:当我尝试运行时,例如:
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()
in a Jupyter notebook, I get the following error message:在 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]))
Deleting the fontList.cache
, fontList.json
, and fontList.py3.cache
删除
fontList.cache
、 fontList.json
和fontList.py3.cache
Uncommenting the font family related sections of the matplotlibrc
file取消注释
matplotlibrc
文件的字体系列相关部分
Uninstalled and reinstalled matplotlib
using pip uninstall matplotlib
and pip install matplotlib
卸载并重新安装
matplotlib
使用pip uninstall matplotlib
和pip install matplotlib
Nothing has solved the issue.什么都没有解决这个问题。 The only possible way for me to get different fonts now is to use LaTeX as the backend, but that's slow and unnecessary.
我现在获得不同字体的唯一可能方法是使用 LaTeX 作为后端,但这很慢而且没有必要。
Any ideas what I can try next?任何想法我接下来可以尝试什么?
Edit: I'm using Windows 10, so not using apt-get
for me.编辑:我使用的是 Windows 10,所以没有为我使用
apt-get
。 That seems to be a common fix for these problems, but I can't do it.这似乎是解决这些问题的常见方法,但我做不到。 It appears those solutions just add Microsoft fonts to the Linux font manager, so it's probably not even relevant since I'm already on a Microsoft machine.
看来这些解决方案只是将 Microsoft 字体添加到 Linux 字体管理器中,因此它甚至可能无关紧要,因为我已经在使用 Microsoft 机器了。
Minimum working Example:最低工作量示例:
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()
In fontList.json
, Computer Modern is listed as an available font.在
fontList.json
,Computer Modern 被列为可用字体。
I had the same issue.我遇到过同样的问题。 For me, changing my matplotlib version from back to
1.5.3
solves the issue.对我来说,将我的 matplotlib 版本从回
1.5.3
解决了这个问题。 You need to pip uninstall matplotlib
first then pip install matplotlib==1.5.3
.您需要先
pip uninstall matplotlib
然后pip install matplotlib==1.5.3
。
More context, I was using ggplot
on zeppelin notebook with Amazon EC2.更多上下文,我在带有 Amazon EC2 的 zeppelin notebook 上使用
ggplot
。 Somehow the matplotlib version installed was 2.2.3
.不知何故,安装的 matplotlib 版本是
2.2.3
。
After changing the version, the error is gone更改版本后,错误消失
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.