Matplotlib.pyplot.savefig() a Python

Matplotlib.pyplot.savefig() a Python

Matplotlib és una biblioteca de visualització molt útil en Python. És una biblioteca de visualització de dades multiplataforma construïda sobre matrius NumPy i dissenyada per funcionar amb la pila SciPy més àmplia. La visualització té un paper molt important, ja que ens ajuda a entendre grans quantitats de dades i extreure coneixement.

Matplotlib.pyplot.savefig()

Com el seu nom indica, s'utilitza el mètode savefig() per desar la figura creada després trama dades. La figura creada es pot desar a les nostres màquines locals mitjançant aquest mètode.

Sintaxi: 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, metadades=Cap)

Paràmetres:

PARÀMETRES DESCRIPCIÓ
fname Nom del fitxer .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()>

Sortida:

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

Sortida: