编辑2017年3月15日下午12:00 CDT:我已经设法修复了程序中的错误,并按设计完成了程序。我要感谢berna111和TigerhawkT3提交的答案,因为他们允许我完成这个项目。再次感谢,堆栈溢出!在
我试图将一系列数组构建的直方图(用numpy生成的数组和使用matplotlib的直方图)保存到.png类型的文件中。我收到以下错误消息:
Traceback (most recent call last):
File "C:/Users/Ryan/PycharmProjects/NWS/weather_data.py", line 475, in <module>
figure1.savefig("{}_temperature.png".format(filename))
AttributeError: 'tuple' object has no attribute 'savefig'
错误涉及的部分如下:
^{pr2}$为什么我会收到这个错误,我如何修复它?如果有人能告诉我,我将不胜感激。在
注意事项:
我在谷歌上做了一些搜索,发现了一些类似的错误,但是没有一个错误被解释为元组。我不知道元组部分是从哪里来的。
直方图创建步骤中的“_graph_array”项是10长1高的维数组。总共10个项目,指定为浮动类型。
保存步骤中的“filename”变量表示包含日期和时间的字符串。
从documentation for ^{} :
从documentation for ^{} :
看起来您应该以调用}的结果。在
savefig
的方式调用hist
,而不是调用{我已经修改了您的代码,并在理解for循环的过程中,随意更改了几行,创建了一个按数字排列的列表:
不会张贴结果图,但这给了我6个小.png文件在同一个文件夹脚本。在
更好的是,您可以使用函数对数据执行所有操作:
^{pr2}$相关问题 更多 >
编程相关推荐