[英]Matplotlib cannot find basic fonts
我在 miniconda 虛擬環境中的 Python 3 上使用 matplotlib 版本 2.0.0。 我正在研究一個沒有 root 權限的 unix 科學計算集群。 我通常通過 ipython 筆記本執行 python 代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用 Times New Roman 字體,但即使在刪除了我從這里找到的字體緩存文件 (fontList.py3k.cache) 之后:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有效果,我得到與上面相同的錯誤。 真型fonts目錄:
path_to_miniconda/miniconda3/envs/conda34/lib/python3.4/site-packages/matplotlib/mpl-data/fonts/ttf/
里面只有 40 個 fonts 類型:DejaVuSerif,DejaVuSans,STIX,cmb, cmt, cmy
知道會發生什么以及如何添加額外的 fonts? 謝謝!
我在miniconda虛擬環境中的Python 3上使用了matplotlib版本2.0.0。 我正在一個沒有root特權的unix科學計算集群上工作。 我通常通過ipython筆記本執行python代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用Times New Roman字體,但即使刪除了從此處找到的字體緩存文件(fontList.py3k.cache),也可以使用它:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有任何效果,我得到了與上述相同的錯誤。 真正的字體目錄:
path_to_miniconda / miniconda3 / envs / conda34 / lib / python3.4 / site-packages / matplotlib / mpl-data / fonts / ttf /
其中只有40種字體類型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道會發生什么以及如何添加其他字體嗎? 謝謝!
我在miniconda虛擬環境中的Python 3上使用了matplotlib版本2.0.0。 我正在一個沒有root特權的unix科學計算集群上工作。 我通常通過ipython筆記本執行python代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用Times New Roman字體,但即使刪除了從此處找到的字體緩存文件(fontList.py3k.cache),也可以使用它:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有任何效果,我得到了與上述相同的錯誤。 真正的字體目錄:
path_to_miniconda / miniconda3 / envs / conda34 / lib / python3.4 / site-packages / matplotlib / mpl-data / fonts / ttf /
其中只有40種字體類型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道會發生什么以及如何添加其他字體嗎? 謝謝!
我在miniconda虛擬環境中的Python 3上使用了matplotlib版本2.0.0。 我正在一個沒有root特權的unix科學計算集群上工作。 我通常通過ipython筆記本執行python代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用Times New Roman字體,但即使刪除了從此處找到的字體緩存文件(fontList.py3k.cache),也可以使用它:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有任何效果,我得到了與上述相同的錯誤。 真正的字體目錄:
path_to_miniconda / miniconda3 / envs / conda34 / lib / python3.4 / site-packages / matplotlib / mpl-data / fonts / ttf /
其中只有40種字體類型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道會發生什么以及如何添加其他字體嗎? 謝謝!
我在miniconda虛擬環境中的Python 3上使用了matplotlib版本2.0.0。 我正在一個沒有root特權的unix科學計算集群上工作。 我通常通過ipython筆記本執行python代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用Times New Roman字體,但即使刪除了從此處找到的字體緩存文件(fontList.py3k.cache),也可以使用它:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有任何效果,我得到了與上述相同的錯誤。 真正的字體目錄:
path_to_miniconda / miniconda3 / envs / conda34 / lib / python3.4 / site-packages / matplotlib / mpl-data / fonts / ttf /
其中只有40種字體類型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道會發生什么以及如何添加其他字體嗎? 謝謝!
我在miniconda虛擬環境中的Python 3上使用了matplotlib版本2.0.0。 我正在一個沒有root特權的unix科學計算集群上工作。 我通常通過ipython筆記本執行python代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用Times New Roman字體,但即使刪除了從此處找到的字體緩存文件(fontList.py3k.cache),也可以使用它:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有任何效果,我得到了與上述相同的錯誤。 真正的字體目錄:
path_to_miniconda / miniconda3 / envs / conda34 / lib / python3.4 / site-packages / matplotlib / mpl-data / fonts / ttf /
其中只有40種字體類型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道會發生什么以及如何添加其他字體嗎? 謝謝!
我在miniconda虛擬環境中的Python 3上使用了matplotlib版本2.0.0。 我正在一個沒有root特權的unix科學計算集群上工作。 我通常通過ipython筆記本執行python代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用Times New Roman字體,但即使刪除了從此處找到的字體緩存文件(fontList.py3k.cache),也可以使用它:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有任何效果,我得到了與上述相同的錯誤。 真正的字體目錄:
path_to_miniconda / miniconda3 / envs / conda34 / lib / python3.4 / site-packages / matplotlib / mpl-data / fonts / ttf /
其中只有40種字體類型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道會發生什么以及如何添加其他字體嗎? 謝謝!
我在miniconda虛擬環境中的Python 3上使用了matplotlib版本2.0.0。 我正在一個沒有root特權的unix科學計算集群上工作。 我通常通過ipython筆記本執行python代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用Times New Roman字體,但即使刪除了從此處找到的字體緩存文件(fontList.py3k.cache),也可以使用它:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有任何效果,我得到了與上述相同的錯誤。 真正的字體目錄:
path_to_miniconda / miniconda3 / envs / conda34 / lib / python3.4 / site-packages / matplotlib / mpl-data / fonts / ttf /
其中只有40種字體類型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道會發生什么以及如何添加其他字體嗎? 謝謝!
我在miniconda虛擬環境中的Python 3上使用了matplotlib版本2.0.0。 我正在一個沒有root特權的unix科學計算集群上工作。 我通常通過ipython筆記本執行python代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用Times New Roman字體,但即使刪除了從此處找到的字體緩存文件(fontList.py3k.cache),也可以使用它:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有任何效果,我得到了與上述相同的錯誤。 真正的字體目錄:
path_to_miniconda / miniconda3 / envs / conda34 / lib / python3.4 / site-packages / matplotlib / mpl-data / fonts / ttf /
其中只有40種字體類型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道會發生什么以及如何添加其他字體嗎? 謝謝!
我在miniconda虛擬環境中的Python 3上使用了matplotlib版本2.0.0。 我正在一個沒有root特權的unix科學計算集群上工作。 我通常通過ipython筆記本執行python代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用Times New Roman字體,但即使刪除了從此處找到的字體緩存文件(fontList.py3k.cache),也可以使用它:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有任何效果,我得到了與上述相同的錯誤。 真正的字體目錄:
path_to_miniconda / miniconda3 / envs / conda34 / lib / python3.4 / site-packages / matplotlib / mpl-data / fonts / ttf /
其中只有40種字體類型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道會發生什么以及如何添加其他字體嗎? 謝謝!
我在miniconda虛擬環境中的Python 3上使用了matplotlib版本2.0.0。 我正在一個沒有root特權的unix科學計算集群上工作。 我通常通過ipython筆記本執行python代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用Times New Roman字體,但即使刪除了從此處找到的字體緩存文件(fontList.py3k.cache),也可以使用它:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有任何效果,我得到了與上述相同的錯誤。 真正的字體目錄:
path_to_miniconda / miniconda3 / envs / conda34 / lib / python3.4 / site-packages / matplotlib / mpl-data / fonts / ttf /
其中只有40種字體類型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道會發生什么以及如何添加其他字體嗎? 謝謝!
我通過設置pyplot參數修復它:
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'serif'
所以你可以使用如下字體(Helvetica,Times New Roman):
ax.set_title('your_title_text',fontname="Times New Roman", fontsize=20)
我在miniconda虛擬環境中的Python 3上使用了matplotlib版本2.0.0。 我正在一個沒有root特權的unix科學計算集群上工作。 我通常通過ipython筆記本執行python代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用Times New Roman字體,但即使刪除了從此處找到的字體緩存文件(fontList.py3k.cache),也可以使用它:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有任何效果,我得到了與上述相同的錯誤。 真正的字體目錄:
path_to_miniconda / miniconda3 / envs / conda34 / lib / python3.4 / site-packages / matplotlib / mpl-data / fonts / ttf /
其中只有40種字體類型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道會發生什么以及如何添加其他字體嗎? 謝謝!
我在miniconda虛擬環境中的Python 3上使用了matplotlib版本2.0.0。 我正在一個沒有root特權的unix科學計算集群上工作。 我通常通過ipython筆記本執行python代碼。 如果我執行基本命令,例如:
import matplotlib.pyplot as plt
plt.scatter([1,5], [1,5])
我收到一條錯誤消息:
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]))
我希望能夠使用Times New Roman字體,但即使刪除了從此處找到的字體緩存文件(fontList.py3k.cache),也可以使用它:
import matplotlib as mpl
fm = mpl.font_manager
fm.get_cachedir()
命令:
mpl.rcParams['font.family'] = ['serif']
mpl.rcParams['font.serif'] = ['Times New Roman']
沒有任何效果,我得到了與上述相同的錯誤。 真正的字體目錄:
path_to_miniconda / miniconda3 / envs / conda34 / lib / python3.4 / site-packages / matplotlib / mpl-data / fonts / ttf /
其中只有40種字體類型:DejaVuSerif,DejaVuSans,STIX,cmb,cmt,cmy
知道會發生什么以及如何添加其他字體嗎? 謝謝!
以上都不適合我。 我必須結合提供的解決方案。
我從Windows 10中的 PyCharm 運行Jupyter 。 這是我的解決方法。 在執行這些步驟之前,請通過import matplotlib.font_manager
導入字體管理器:
matplotlib.font_manager.findSystemFonts(fontpaths=None, fontext='ttf')
matplotlib.matplotlib_fname()
pdf.fonttype: 42 # Output Type 3 (Type3) or Type 42 (TrueType)
\matplotlib\__pycache__
文件夾。plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.serif'] = ['Lin Libertine']
如果您重新啟動 kernel,如果會生成緩存文件,因此您需要再次刪除它們。
我的情況是我在 Docker 中運行 JupyterHub,我需要使用matplotlib
到 plot 並顯示一些漢字作為標題。
這是我安裝新 fonts 並獲得新 fonts 工作的方法(無需重新啟動 Jupyter 容器):
Docker 鏡像版本:
matplotlib.__version__
:3.1.2所有操作都在容器內執行。
將 fonts 下載到/.../python3.7/site-packages/matplotlib/mpl-data/fonts/ttf
在筆記本中重建字體緩存。 ~/.cache/matplotlib/
( AttributeError: module 'matplotlib' has no attribute 'font_manager' )。
import matplotlib.font_manager
matplotlib.font_manager._rebuild()
字體緩存是基於每個用戶的( /home/{username}/.cache/matplotlib/
),因此其他人可能也需要重建緩存。
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif'] = ['SimSun']
您可能需要在第 2 步和第 3 步中重新啟動筆記本/內核。
筆記:
我試過sudo apt install msttcorefonts -qq
但我認為這不起作用。 我也不知道那個 package 安裝了什么。 apt-file list msttcorefonts
什么也不返回。
為什么apt-file list msttcorefonts
什么也不返回?
有一個配置文件/.../python3.7/site-packages/matplotlib/mpl-data/matplotlibrc
可以在其中添加font.sans-serif
fonts。 但無需修改,新的 fonts 也可以工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.