Matplotlib.pyplot.savefig() in Python

Matplotlib.pyplot.savefig() in Python

Matplotlib ist eine äußerst nützliche Visualisierungsbibliothek in Python. Es handelt sich um eine plattformübergreifende Datenvisualisierungsbibliothek, die auf NumPy-Arrays basiert und für die Zusammenarbeit mit dem breiteren SciPy-Stack konzipiert ist. Visualisierung spielt eine sehr wichtige Rolle, da sie uns hilft, große Datenmengen zu verstehen und Wissen zu extrahieren.

Matplotlib.pyplot.savefig()

Wie der Name schon sagt, wird die Methode savefig() verwendet, um die danach erstellte Figur zu speichern Plotten Daten. Mit dieser Methode kann die erstellte Figur auf unseren lokalen Rechnern gespeichert werden.

Syntax: savefig(fname, dpi=Keine, Gesichtsfarbe='w', Kantenfarbe='w', Ausrichtung='Porträt', Papiertyp=Keine, Format=Keine, transparent=Falsch, bbox_inches=Keine, pad_inches=0.1, Frameon=Keine, Metadaten=Keine)

Parameter:

PARAMETER BESCHREIBUNG
fname Dateiname .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()>

Ausgabe :

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

Ausgabe :