首页IT科技find复合结构讲解(findfont: Font family [‘Times New Roman‘] not found. Falling back to DejaVu Sans.)

find复合结构讲解(findfont: Font family [‘Times New Roman‘] not found. Falling back to DejaVu Sans.)

时间2025-05-05 13:01:52分类IT科技浏览8307
导读:问题背景: 远程使用服务器绘图时,设置font_dict中字体格式为Times New Roman,如下:...

问题背景:

远程使用服务器绘图时                ,设置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. 

        方法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()

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

 然后删除该文件夹           。 

参考: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. - 灰信网(软件开发博客聚合)

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
js数字失真怎么解决(教你一文解决 js 数字精度丢失问题)