Matplotlib.pyplot.savefig() in Python

Matplotlib.pyplot.savefig() in Python

Matplotlib is een zeer nuttige visualisatiebibliotheek in Python. Het is een datavisualisatiebibliotheek met meerdere platforms, gebouwd op NumPy-arrays en ontworpen om te werken met de bredere SciPy-stack. Visualisatie speelt een zeer belangrijke rol omdat het ons helpt grote hoeveelheden gegevens te begrijpen en kennis te extraheren.

Matplotlib.pyplot.savefig()

Zoals de naam al doet vermoeden, wordt de methode savefig() gebruikt om het daarna gemaakte figuur op te slaan plotten gegevens. Het gemaakte figuur kan met behulp van deze methode op onze lokale machines worden opgeslagen.

Syntaxis: savefig(fname, dpi=Geen, facecolor='w', edgecolor='w', oriëntatie='portret', papertype=Geen, format=Geen, transparant=False, bbox_inches=Geen, pad_inches=0.1, frameon=Geen, metagegevens=Geen)



Parameters:

PARAMETERS BESCHRIJVING
fnaam Bestandsnaam .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()>

Uitgang:

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

Uitgang:



Top Artikelen

Categorie

Interessante Artikelen