簡體   English   中英

Matplotlib 報告找不到字體系列“襯線”

[英]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]))

我嘗試過的事情:

  1. 刪除fontList.cachefontList.jsonfontList.py3.cache

  2. 取消注釋matplotlibrc文件的字體系列相關部分

  3. 卸載並重新安裝matplotlib使用pip uninstall matplotlibpip 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM