问题背景:

远程使用服务器绘图时,设置font_dict中字体格式为'Times New Roman',如下:

font_dict=dict(fontsize=16,
              color='black',
              family='Times New Roman',
            #   weight='light',
              style='italic',
              )

在绘图的过程中报出以下错误:

findfont: Font family ['Times New Roman'] not found. Falling back to DejaVu Sans.

错误原因:

服务器上缺少Times New Roman对应字体文件。


解决方案:

在服务器上安装 Times New Roman 字体文件。

step1:获取Times New Roman字体文件

        方法1(推荐):

        从win10系统上寻找,寻找路径是:‘C:\Windows\Fonts’,搜索“Times New Roman”,搜索结果如下。复制该文件到桌面,可以得到四个文件:times.tiff, timesbd.tiff, timesbi.tiff, timesi.tiff. 

findfont: Font family [‘Times New Roman‘] not found. Falling back to DejaVu Sans.

        方法2:

        从网络上下载,下载网址是http://www.xiazaiziti.com/?s=times+new+roman.

step2:复制“time new roman”文件到服务器上

        把四个“time new roman”文件复制到服务器上  matplotlib库对应的 fonts/ttf 文件夹下,我的路径是“/home/wzg/anaconda3/envs/LSTM-C3D-GAN/lib/python3.6/site-packages/matplotlib/mpl-data/fonts/ttf”,该路径可以通过以下代码查看:

python
>>> import matplotlib
>>> print(matplotlib.matplotlib_fname())

step3:删除之前的字体缓存

        方法1:

        手工找到“home/wzg/.cache/matplotlib”目录并删除该目录,地址中的wzg是用户名,根据实际情况自行更改。如果找不到cache文件夹,是因为其为隐藏文件夹,可ctrl+h将其显示。

        方法2:

        在终端窗口输入以下指令寻找“home/wzg/.cache/matplotlib”目录,

python
>>> import matplotlib
>>> matplotlib.get_cachedir() 

找到隐藏的文件夹,如下图所示,

findfont: Font family [‘Times New Roman‘] not found. Falling back to DejaVu Sans.

 然后删除该文件夹。 

参考:Linux下的python修改画图的字体_刘西北的博客-CSDN博客_linux python 字体

使用matplotlib时缺失字体,findfont: Font family [‘Times New Roman‘] not found. Falling back to DejaVu Sans._ixobgenw的博客-CSDN博客

1238: UserWarning: findfont: Font family [‘sans-serif’] not found. Falling back to DejaVu Sans. - 灰信网(软件开发博客聚合)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。