logo

Matplotlib.pyplot.savefig() en Python

Matplotlib est une bibliothèque de visualisation très utile en Python. Il s'agit d'une bibliothèque de visualisation de données multiplateforme construite sur des tableaux NumPy et conçue pour fonctionner avec la pile SciPy plus large. La visualisation joue un rôle très important car elle nous aide à comprendre d’énormes quantités de données et à extraire des connaissances.

Natasha Dalal

Matplotlib.pyplot.savefig()

Comme son nom l'indique, la méthode savefig() est utilisée pour enregistrer la figure créée après traçage données. La figure créée peut être enregistrée sur nos machines locales en utilisant cette méthode.



Syntaxe: savefig(fname, dpi=Aucun, facecolor='w', edgecolor='w', orientation='portrait', papertype=Aucun, format=Aucun, transparent=False, bbox_inches=Aucun, pad_inches=0.1, frameon=Aucun, métadonnées = Aucune)

Paramètres:

PARAMÈTRES DESCRIPTION
nom de famille Nom du fichier .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()>

>

>

Sortir :

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

>

>

Sortir :