【发布时间】:2020-02-01 02:23:05
【问题描述】:
我正在使用 google colab,并且正在尝试使用“Times New Roman”字体进行 matplotlib 绘图。由于 google colab 中的 ttf 文件位于/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf 所以我所做的是从https://github.com/trishume/OpenTuringCompiler/blob/master/stdlib-sfml/fonts/Times%20New%20Roman.ttf 下载“Times New Roman”的 ttf 文件并运行命令!wget https://github.com/trishume/OpenTuringCompiler/blob/master/stdlib-sfml/fonts/Times%20New%20Roman.ttf -P /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf 基本上将 tff 文件下载到字体文件夹中谷歌 colab 中的 matplotlib。
在此之后,当我尝试使用 matplotlib.font_manager.findfont('Times New Roman') 时,它给了我一个错误,如下所示。因此我无法在绘图中使用该字体。
所以我无法找到问题所在,因为我亲自检查并找到了上述字体的 tff 文件。
请帮忙
!wget https://github.com/trishume/OpenTuringCompiler/blob/master/stdlib-sfml/fonts/Times%20New%20Roman.ttf -P /usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf
font_manager.findfont('Times New Roman')
/usr/local/lib/python3.6/dist-packages/matplotlib/font_manager.py:1241: UserWarning: findfont: Font family ['Times New Roman'] not found. Falling back to DejaVu Sans.
(prop.get_family(), self.defaultFamily[fontext]))
【问题讨论】:
-
可能相关:stackoverflow.com/questions/51810908/…。诚然,我对 Google colab 知之甚少,但这似乎是一个类似的问题。
-
我使用了相同的方法,但它不起作用
-
至少从您在问题中写的内容来看,您还没有完成重建步骤。
-
对不起,我这样做了,但忘了在这里提及
标签: python matplotlib fonts google-colaboratory