PyPlot保存图像时出现错误:“使用ttc字体时缺少TrueType表”。

5

我正在macOS 10.13上使用Julia语言的PyPlot软件包。以下是生成问题的代码:

using PyPlot
PyPlot.svg(true)

function myplot()
  my_font=matplotlib[:font_manager][:FontProperties](fname = "/System/Library/Fonts/Helvetica.ttc")
  fig, ax = subplots()
  ax[:plot](rand(10), rand(10), linewidth = 2)

  for tick in ax[:xaxis][:get_major_ticks]()
    tick[:label][:set_fontproperties](my_font)
  end
  for tick in ax[:yaxis][:get_major_ticks]()
    tick[:label][:set_fontproperties](my_font)
  end
  savefig("figure.pdf")
end

myplot()

正如您所看到的,我需要将刻度标签的字体更改为Helvetica,该字体通过ttc文件在我的mac上可用。该图在Jupyter Notebook中正常显示。但是,使用savefig()时,它不起作用:

RuntimeError('TrueType font is missing table',)

我已经删除了~/.matplotlib/fontList.py3k.cache~/.matplotlib/tex.cache。为了使savefig()起作用,我还需要做什么?谢谢!

1个回答

0

我建议你应该换一种字体

matplotlib.rcParams['font.family'] = 'Calibri'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接