我尝试运行此代码,用代码绘制一个简单的散点图:
plt.subplot(111)
plt.plot(x, y, linewidth=1.0)
plt.savefig('P_vs_time.pdf')
但是我收到以下错误:
Traceback (most recent call last):
File "~/python/test.py", line 295, in <module>
plt.savefig('P_vs_time.pdf', bbox_inches='tight')
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 561, in savefig
return fig.savefig(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1421, in savefig
self.canvas.print_figure(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 2167, in print_figure
**kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_pdf.py", line 2358, in print_pdf
file.close()
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_pdf.py", line 507, in close
self.writeFonts()
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_pdf.py", line 607, in writeFonts
fonts[Fx] = self.embedTTF(realpath, chars[1])
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_pdf.py", line 1008, in embedTTF
ps_name = sfnt[(3,1,0x0409,6)].decode('utf-16be')
KeyError: (3, 1, 1033, 6)
为什么会这样?
答案 0 :(得分:0)
我认为问题在于您在创建绘图后没有添加plt.show()
。所以试着这样做:
plt.subplot(111)
plt.plot(x, y, linewidth=1.0)
plt.show()
plt.savefig('P_vs_time.pdf')