2013-09-24 2 views
38

に保存するipythonノートブックでは、まずpandasシリーズオブジェクトを作成し、インスタンスメソッド.hist()を呼び出すと、ブラウザに図が表示されます。pandas.Seriesヒストグラムプロットをファイル

この図をファイルに保存する方法を教えています(私は右クリックして名前を付けて保存するのではなく、スクリプトに必要なコマンドを使用します)。

答えて

84

そうのように、Figure.savefig()メソッドを使用します。

ax = s.hist() # s is an instance of Series 
fig = ax.get_figure() 
fig.savefig('/path/to/figure.pdf') 

それはpdfで終了する必要はありません、多くのオプションがあります。 the documentationをチェックしてください。

また、あなたはpyplotインタフェースを使用することができ、ちょうど最近作成した図節約する機能としてsavefigを呼び出す:明確にするために

import matplotlib.pyplot as plt 
s.hist() 
plt.savefig('path/to/figure.pdf') # saves the current figure 
+7

を: 'savefig'は、matplotlib.pyplot''の関数であり、完全な呼び出しは 'import matplotlib.pyplot as plt;となります。 plt.savefig( 'image.png') ' –

関連する問題