我有一个使用matplotlib和python创建和保存绘图的代码。代码在我的主管的笔记本电脑上完美运行,他的主管有matplotlib 1.1.1。但是,尽管我有更新版本的matplotlib(1.3.1),但在执行此命令时出现以下错误:
plt.savefig("outputs/" + run_uuid +".pdf", facecolor='white', bbox_inches='tight', pad_inches=0.0)
我在该命令上获得以下Traceback:
Traceback (most recent call last):
File "vis.py", line 1116, in <module>
plt.savefig("outputs/" + run_uuid +".pdf", facecolor='white', bbox_inches='tight', pad_inches=0.0)
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/backend_bases.py", line 1952, in print_pdf
return pdf.print_pdf(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/backends/backend_pdf.py", line 2352, in print_pdf
self.figure.draw(renderer)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/figure.py", line 1034, in draw
func(*args)
File "/usr/lib/pymodules/python2.7/mpl_toolkits/axisartist/axislines.py", line 774, in draw
super(Axes, self).draw(renderer, inframe)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 2086, in draw
a.draw(renderer)
File "/usr/lib/pymodules/python2.7/matplotlib/artist.py", line 55, in draw_wrapper
draw(artist, renderer, *args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/lines.py", line 530, in draw
gc.set_foreground(ln_color_rgba)
File "/usr/lib/pymodules/python2.7/matplotlib/backend_bases.py", line 921, in set_foreground
self._rgb = colors.colorConverter.to_rgba(fg)
File "/usr/lib/pymodules/python2.7/matplotlib/colors.py", line 365, in to_rgba
'to_rgba: Invalid rgba arg "%s"\n%s' % (str(arg), exc))
ValueError: to_rgba: Invalid rgba arg "None"
to_rgb: Invalid rgb arg "None"
cannot convert argument to rgb sequence
我在网上找不到任何有用的错误。你知道我做错了吗?
我也尝试重写这个
plt.savefig("outputs/" + run_uuid +".pdf", facecolor='white', bbox_inches='tight', pad_inches=0.0)
到此:
plt.savefig("outputs/" + run_uuid +".pdf")
但没有任何进展
答案 0 :(得分:1)
我认为理由是facecolor没有“白色”的价值。
从the following link开始,脸部颜色设置中不存在“白色”。
如果只使用plt.savefig(“你的路径”)怎么办?我认为默认背景颜色应该是白色。