Matplotlib.pyplot.savefig() Pythonissa

Matplotlib.pyplot.savefig() Pythonissa

Matplotlib on erittäin hyödyllinen visualisointikirjasto Pythonissa. Se on monikäyttöinen tietojen visualisointikirjasto, joka on rakennettu NumPy-taulukoihin ja suunniteltu toimimaan laajemman SciPy-pinon kanssa. Visualisoinnilla on erittäin tärkeä rooli, koska se auttaa meitä ymmärtämään valtavia datapaloja ja poimimaan tietoa.

Matplotlib.pyplot.savefig()

Kuten nimestä voi päätellä, savefig() -menetelmää käytetään jälkeen luodun kuvan tallentamiseen juonittelu tiedot. Luotu hahmo voidaan tallentaa paikallisille koneillemme tällä menetelmällä.

Syntaksi: savefig(fname, dpi=Ei mitään, facecolor='w', edgecolor='w', orientation='pysty', papertype=Ei mitään, format=Ei mitään, transparent=False, bbox_inches=Ei mitään, pad_inches=0.1, frameon=Ei mitään, metatiedot = Ei mitään)

Parametrit:

PARAMETRIT KUVAUS
fname Tiedostonimi .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()>

Lähtö:

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

Lähtö: