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