Livre_silo 30 août 2013 16:32 Page 233
¨
©
¨
©
¨
©
¨
©
C o p y r i g h t E y r o l l e s
233
9 – Résolution numérique d’équations différentielles
mon-premier-plot.pdf
Figure 9.8
Graphe d’une fonction, avec un titre, une grille, etc.
PROGRAMME 8 Utilisation de matplotlib
import matplotlib.pyplot as pl
import numpy as np
def f(t):
return np.sin(5*t) * np.exp(t)
x = np.linspace(-np.pi, np.pi, 100)
y = f(x)
pl.plot(x, y)
pl.grid() # décoration : pour créer une grille
pl.title('Le graphe de $f$') # Le titre
pl.xlabel('$x$') # le nom de l'axe horizontal
pl.ylabel('$y=f(x)$')
pl.axhline(color='black') #linewidth=1, color='k')
pl.axvline(color='black')
pl.savefig('mon-premier-plot.pdf') # pour sauver (en pdf ou autre)
pl.show() # le show doit etre APRES la sauvegarde !
¨
©
¨
©
¨
©
¨
©
C o p y r i g h t E y r o l l e s
233
9 – Résolution numérique d’équations différentielles
mon-premier-plot.pdf
Figure 9.8
Graphe d’une fonction, avec un titre, une grille, etc.
PROGRAMME 8 Utilisation de matplotlib
import matplotlib.pyplot as pl
import numpy as np
def f(t):
return np.sin(5*t) * np.exp(t)
x = np.linspace(-np.pi, np.pi, 100)
y = f(x)
pl.plot(x, y)
pl.grid() # décoration : pour créer une grille
pl.title('Le graphe de $f$') # Le titre
pl.xlabel('$x$') # le nom de l'axe horizontal
pl.ylabel('$y=f(x)$')
pl.axhline(color='black') #linewidth=1, color='k')
pl.axvline(color='black')
pl.savefig('mon-premier-plot.pdf') # pour sauver (en pdf ou autre)
pl.show() # le show doit etre APRES la sauvegarde !
