編集2017年3月15日12:00 PM CDT:私はプログラムでエラーを修正し、それを設計したとして、プログラムを完了するために管理しています。彼らが私にこのプログラムを完了させるのを許してくれたので、berna1111とTigerhawkT3に答えてくれたことに感謝したいと思います。もう一度、スタックオーバーフローありがとう!なぜ "AttributeError: 'tuple'オブジェクトに属性 'savefig'がありませんか?
私はタイプ.pngファイルするために、アレイ内蔵ヒストグラム(matplotlibのを使用してnumpyのヒストグラムで作られた配列)のシリーズを保存しようとしています。私は、次のエラーメッセージを受信しています:
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'
エラーが参照するセクションは以下の通りです:
figure1 = plt.hist(temperature_graph_array, color="blue")
figure2 = plt.hist(feelslike_graph_array, color="blue")
figure3 = plt.hist(windspeed_graph_array, color="blue")
figure4 = plt.hist(windgustspeed_graph_array, color="blue")
figure5 = plt.hist(pressure_graph_array, color="blue")
figure6 = plt.hist(humidity_graph_array, color="blue")
figure1.savefig("{}_temperature.png".format(filename), format='png')
figure2.savefig("{}_feelslike.png".format(filename), format='png')
figure3.savefig("{}_windspeed.png".format(filename), format='png')
figure4.savefig("{}_windgustspeed.png".format(filename), format='png')
figure5.savefig("{}_pressure.png".format(filename), format='png')
figure6.savefig("{}_humidity.png".format(filename), format='png')
は、なぜ私はこのエラーが発生します、そしてどのように私はそれを修正することができますか?誰かが私に教えてくれたら、私はそれを大いに感謝するでしょう。
注:
私はいくつかのGoogle検索を行って、いくつかの同様のエラーが、数字は、タプルとして解釈されたなしを発見しました。タプルの部分がどこから来ているのか分かりません。
ヒストグラム作成ステップの「_グラフ配列」アイテムは、長さ10の長さが1の高さの配列です。内部に合計10個のアイテムがあり、フロートタイプとして指定されています。
保存ステップの "filename"変数は、日付と時刻を含む文字列を表します。
documentation formatplotlib.pyplot.hist
から
plt.hist'は 'figure' instaceを返しません'、あなたは数字( 'FIG1 = PLTを作成する必要があります。( 'ax1 = fig1.add_subplots(111)')、次に軸( 'ax1.hist(...)')を描画します。その時点で、Figureを保存することができます( 'fig1.savefig(...)')。テスト後に回答を投稿します。 – berna1111
修正: 'ax1 = fig1.add_subplot' * s *'(111) 'ではなく、' ax1 = fig1.add_subplot(111) '! – berna1111