Matplotlib.pyplot.savefig() in Python

Matplotlib.pyplot.savefig() in Python

Matplotlib è una libreria di visualizzazione molto utile in Python. Si tratta di una libreria di visualizzazione dati multipiattaforma costruita su array NumPy e progettata per funzionare con lo stack SciPy più ampio. La visualizzazione gioca un ruolo molto importante poiché ci aiuta a comprendere enormi quantità di dati ed estrarre conoscenza.

Matplotlib.pyplot.savefig()

Come suggerisce il nome, il metodo savefig() viene utilizzato per salvare la figura creata successivamente complottando dati. La figura creata può essere salvata sui nostri computer locali utilizzando questo metodo.

Sintassi: savefig(fname, dpi=Nessuno, facecolor='w', edgecolor='w', orientamento='ritratto', papertype=Nessuno, format=Nessuno, trasparente=False, bbox_inches=Nessuno, pad_inches=0.1, frameon=Nessuno, metadati=Nessuno)

parametri:

PARAMETRI DESCRIZIONE
nomef Nome file .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()>

Produzione :

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

Produzione :