Matplotlib.pyplot.savefig() en Python

Matplotlib.pyplot.savefig() en Python

Matplotlib es una biblioteca de visualización muy útil en Python. Es una biblioteca de visualización de datos multiplataforma construida sobre matrices NumPy y diseñada para funcionar con la pila SciPy más amplia. La visualización juega un papel muy importante ya que nos ayuda a comprender grandes cantidades de datos y extraer conocimiento.

Matplotlib.pyplot.savefig()

Como su nombre indica, el método savefig() se utiliza para guardar la figura creada después Graficado datos. La figura creada se puede guardar en nuestras máquinas locales utilizando este método.

Sintaxis: savefig(fname, dpi=Ninguno, facecolor='w', edgecolor='w', orientación='retrato', tipo de papel=Ninguno, formato=Ninguno, transparente=False, bbox_inches=Ninguno, pad_inches=0.1, frameon=Ninguno, metadatos=Ninguno)

Parámetros:

PARÁMETROS DESCRIPCIÓN
nombref Nombre de archivo .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()>

Producción :

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

Producción :