Qua*_*sim 3 python fonts matplotlib google-colaboratory
我正在使用 google colab,并且尝试使用“Times New Roman”字体进行 matplotlib 绘图。由于google colab中的ttf文件位于,/usr/local/lib/python3.6/dist-packages/matplotlib/mpl-data/fonts/ttf所以我所做的就是下载“Times New Roman”的ttf文件https://github.com/trishume/OpenTuringCompiler/blob/master/stdlib-sfml/fonts/Times%20New%20Roman.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文件下载到google 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')
Run Code Online (Sandbox Code Playgroud)
/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]))
Run Code Online (Sandbox Code Playgroud)
小智 5
import matplotlib.pyplot as plt
plt.rcParams['font.family'] = 'serif'
plt.rcParams['font.serif'] = ['Times New Roman'] + plt.rcParams['font.serif']
Run Code Online (Sandbox Code Playgroud)
我认为这会起作用。
| 归档时间: |
|
| 查看次数: |
6229 次 |
| 最近记录: |