savefig(newbie)的Python Matplotlib错误. [英] Python Matplotlib errors with savefig (newbie).

查看:68
本文介绍了savefig(newbie)的Python Matplotlib错误.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计算机上Python的所有部分最近都是从Enthought学术软件包中安装的,但是使用Pyscripter来编辑和运行代码.我的学习曲线还很早,所以很可能会忽略这里的一些明显的事情.

All parts of Python on my computer were recently installed from the Enthought academic package, but use Pyscripter for editing and running code. I'm very early in my learning curve, and so could very well be overlooking some obvious things here.

当我尝试创建图并保存时,如下所示:

When I try to create a plot and save it like so:

import matplotlib.pylab as pl
pl.hist(myEst, bins=20, range=(.1,.60))
pl.ylabel("Freq")
pl.xlabel("Success Probability")
pl.title('Histogram of Binomial Estimator')
pl.axis([0, 1, 0, 500])
pl.vlines (.34,0,500) 
pl.savefig('TestHist.png')
pl.show()

我收到这些错误:

Traceback (most recent call last):
  File "<editor selection>", line 9, in <module>
  File "C:\Python27\lib\site-packages\matplotlib\figure.py", line 1172, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_wxagg.py", line 100, in print_figure
    FigureCanvasAgg.print_figure(self, filename, *args, **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\backend_bases.py", line 2017, in print_figure
    **kwargs)
  File "C:\Python27\lib\site-packages\matplotlib\backends\backend_agg.py", line 450, in print_png
    filename_or_obj = file(filename_or_obj, 'wb')
IOError: [Errno 13] Permission denied: 'TestHist.png'

如果我取出 pl.savefig('TestHist') 行,一切正常,我可以看到我想要的图,但是当该行在那里时,我会收到错误消息.

If I take out the pl.savefig('TestHist') line everything works fine, and I can see the plot I want, but when that line is in there I get the errors.

我已经使用pl.get_backend()检查了后端版本,它返回了"WXAgg",根据文档,它应该能够使用.png格式.

I've checked my backend version using pl.get_backend(), it returns 'WXAgg', which according to documentation should be able to use .png format.

我还尝试在 savefig 命令中包含显式的 format='png'format=png,但仍然出现错误

I've also tried including an explicit format='png' and format=png within the savefig command, but still get errors.

谁能给我一些关于如何进行的建议,或者另一种保存情节的方法?

Can anyone give me advice on how to proceed, or another approach for saving a plot?

推荐答案

如果它可以帮助其他人,我犯了一个愚蠢的错误,即没有实际指定文件名,结果返回了相同的错误消息,导致我遇到了这个问题以供审核.

If it helps others, I made the silly mistake of not actually designating a file name and as a result had returned the same error message that lead me to this question for review.

这是生成错误的代码:

plt.savefig('C:\\Users\\bwarn\\Canopy', format='png')

这是我已解决的更正(您会看到我指定了实际文件和名称)

Here is my correction that resolved (you'll see I designated the actual file and name)

plt.savefig('C:\\Users\\bwarn\\Canopy\\myplot.png', format='png')

这篇关于savefig(newbie)的Python Matplotlib错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆