Python の Matplotlib.pyplot.savefig()

Python の Matplotlib.pyplot.savefig()

マットプロットリブ は、Python の非常に便利な視覚化ライブラリです。これは、NumPy 配列に基づいて構築され、より広範な SciPy スタックで動作するように設計されたマルチプラットフォーム データ視覚化ライブラリです。視覚化は、膨大な量のデータを理解し、知識を抽出するのに役立つため、非常に重要な役割を果たします。

Matplotlib.pyplot.savefig()

名前が示すように、savefig() メソッドは、作成後に作成された Figure を保存するために使用されます。 プロット データ。この方法を使用すると、作成した図をローカル マシンに保存できます。

構文: savefig(fname、dpi=None、facecolor='w'、edgecolor='w'、orientation='portrait'、papertype=None、format=None、transparent=False、bbox_inches=None、pad_inches=0.1、frameon=None、メタデータ=なし)

パラメーター:

パラメーター 説明
fname ファイル名 .webp'コードブロック'>




# importing required modules> import> matplotlib.pyplot as plt> > # creating plotting data> xaxis> => [> 1> ,> 4> ,> 9> ,> 16> ,> 25> ,> 36> ,> 49> ,> 64> ,> 81> ,> 100> ]> yaxis> => [> 1> ,> 2> ,> 3> ,> 4> ,> 5> ,> 6> ,> 7> ,> 8> ,> 9> ,> 10> ]> > # plotting> plt.plot(xaxis, yaxis)> plt.xlabel(> 'X'> )> plt.ylabel(> 'Y'> )> > # saving the file.Make sure you> # use savefig() before show().> plt.savefig(> 'squares.webp'> )> > plt.show()>

出力:

例 2:




# importing the modules> import> matplotlib.pyplot as plt> > > # creating data and plotting a histogram> x> => [> 1> ,> 4> ,> 9> ,> 16> ,> 25> ,> 36> ,> 49> ,> 64> ,> 81> ,> 100> ]> plt.hist(x)> > # saving the figure.> plt.savefig(> 'squares1.webp'> ,> > bbox_inches> => 'tight'> ,> > pad_inches> => 1> ,> > transparent> => True> ,> > facecolor> => 'g'> ,> > edgecolor> => 'w'> ,> > orientation> => 'landscape'> )> > plt.show()>

出力:



あなたにおすすめ