Fungsi plt.savefig[]
perlu dipanggil tepat di atas garis plt.show[]
. Semua fitur plot harus ditentukan sebelum plot disimpan sebagai file gambar. Jika gambar disimpan setelah perintah plt.show[]
; . Memanggil plt.savefig[]
setelah menelepon plt.show[]
dapat menimbulkan masalah saat membangun plot di notebook Jupyter dengan %matplotlib inline
diaktifkan
Perintah savefig[]
standar adalah
plt.savefig['plot.png', dpi=300, bbox_inches='tight']
Di mana
import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline_0 adalah nama file gambar yang disimpan. Matplotlib menyimpulkan format file gambar [. png,. jpg, dll] berdasarkan ekstensi yang ditentukan dalam nama filex = [0, 2, 4, 6] y = [1, 3, 4, 8]
plt.plot[x,y]
plt.xlabel['x values'] plt.ylabel['y values'] plt.title['plotted x and y values'] plt.legend[['line 1']]
# save the figure plt.savefig['plot.png', dpi=300, bbox_inches='tight']
plt.show[]
Argumen kata kunci
import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline_4 adalah opsional. Jika label sumbu pada plot terpotong pada gambar yang disimpan, aturx = [0, 2, 4, 6] y = [1, 3, 4, 8]
plt.plot[x,y]
plt.xlabel['x values'] plt.ylabel['y values'] plt.title['plotted x and y values'] plt.legend[['line 1']]
# save the figure plt.savefig['plot.png', dpi=300, bbox_inches='tight']
plt.show[]
import matplotlib.pyplot as plt # if using a Jupyter notebook, include: %matplotlib inline4x = [0, 2, 4, 6] y = [1, 3, 4, 8]
plt.plot[x,y]
plt.xlabel['x values'] plt.ylabel['y values'] plt.title['plotted x and y values'] plt.legend[['line 1']]
# save the figure plt.savefig['plot.png', dpi=300, bbox_inches='tight']
plt.show[]