logo

Matplotlib.pyplot.savefig() în Python

Matplotlib este o bibliotecă de vizualizare extrem de utilă în Python. Este o bibliotecă de vizualizare a datelor multi-platformă construită pe matrice NumPy și concepută pentru a funcționa cu stiva SciPy mai largă. Vizualizarea joacă un rol foarte important, deoarece ne ajută să înțelegem cantități uriașe de date și să extragem cunoștințe.

Matplotlib.pyplot.savefig()

După cum sugerează și numele, metoda savefig() este folosită pentru a salva figura creată după complotând date. Cifra creată poate fi salvată pe mașinile noastre locale utilizând această metodă.

Sintaxă: 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, metadate=Niciuna)



Parametri:

PARAMETRI DESCRIERE
fname Nume fișier .webp'code-block'>




# 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()>

>

>

Ieșire:

Exemplul 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()>

>

>

Ieșire:

valoare șir de