Différences
Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
matplotlib [Le 22/03/2015, 10:48] – G-Tux | matplotlib [Le 18/10/2020, 21:05] (Version actuelle) – [Depuis les dépôts] 86.246.31.132 | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
+ | {{tag> | ||
+ | ---- | ||
+ | |||
+ | ====== Matplotlib ====== | ||
+ | |||
+ | **Matplotlib** est une bibliothèque Python permettant de réaliser des graphiques en 2D et 3D | ||
+ | |||
+ | \\ | ||
+ | |||
+ | ===== Pré-requis ===== | ||
+ | |||
+ | * Disposer des [[: | ||
+ | * Disposer d'une connexion à Internet configurée et activée. | ||
+ | |||
+ | ===== Installation ===== | ||
+ | ==== Depuis les dépôts ==== | ||
+ | |||
+ | [[: | ||
+ | |||
+ | Ou par le terminal : | ||
+ | < | ||
+ | sudo apt-get install python-matplotlib</ | ||
+ | |||
+ | en python 3 : | ||
+ | < | ||
+ | sudo apt-get install python3-matplotlib</ | ||
+ | ===== Utilisation ===== | ||
+ | |||
+ | Exemple d'un graphique en 2D (tiré de [[http:// | ||
+ | Créer un fichier et y coller le code : | ||
+ | <file python spirale.py> | ||
+ | # | ||
+ | from pylab import * | ||
+ | rc(' | ||
+ | figure(figsize = (6, 6)) | ||
+ | ax = axes([0.1, 0.1, 0.8, 0.8], polar = True) | ||
+ | t = arange(-4 * pi, 4 * pi, .1) | ||
+ | polar(t, 1.19**t, linewidth = 2) | ||
+ | xt, yt = xticks()[0], | ||
+ | xticks(xt, ['' | ||
+ | yticks(yt, ['' | ||
+ | savefig(' | ||
+ | show()</ | ||
+ | \\ | ||
+ | Sauvegarder et rendre le fichier exécutable.\\ | ||
+ | Lancer le code, par exemple en ligne de commande :< | ||
+ | vous obtiendrez : | ||
+ | |||
+ | {{ :: | ||
+ | |||
+ | Autre exemple d' | ||
+ | Créer un fichier et y coller le code : | ||
+ | <file python graphs.py> | ||
+ | # | ||
+ | |||
+ | """ | ||
+ | # Original: Peter Halasz. 2010-09-14 | ||
+ | # Enhanced: Ika. 2013-07-23 | ||
+ | |||
+ | import numpy as np | ||
+ | from pylab import * | ||
+ | from mpl_toolkits.mplot3d import Axes3D | ||
+ | |||
+ | graphs = {' | ||
+ | |||
+ | for gr in graphs: | ||
+ | ax = Axes3D(figure(), | ||
+ | X = arange(-2*pi, | ||
+ | Y = arange(-4, 4, .2) | ||
+ | X, Y = meshgrid(X, Y) | ||
+ | fn = graphs[gr] | ||
+ | Z = fn(arcsin(X + Y*1j)) | ||
+ | ax.plot_surface(X, | ||
+ | ax.contour(X, | ||
+ | ax.set_xlabel(" | ||
+ | ax.set_ylabel(" | ||
+ | ax.set_zlabel(gr + ' | ||
+ | plt.savefig(" | ||
+ | </ | ||
+ | \\ | ||
+ | Sauvegarder et rendre le fichier exécutable. | ||
+ | Lancer le code, vous obtiendrez les figures suivantes : | ||
+ | \\ | ||
+ | {{:: | ||
+ | {{ :: | ||
+ | {{:: | ||
+ | {{ :: | ||
+ | |||
+ | ===== Voir aussi ===== | ||
+ | |||
+ | * [[http:// | ||
+ | * [[Gnuplot]] | ||
+ | * [[http:// | ||
+ | |||
+ | ---- | ||
+ | |||
+ | // |