Matplotlib: graphe 2D

From Wiki Cours
Revision as of 10:41, 16 July 2015 by Wiki-cours (talk | contribs) (Created page with "== Création d'un graphe 2D == On utilise la bibliothèque '''Pylab''' de matplotlib <source lang="py"> from pylab import * #t = arange(0.0, 2.01, 0.01) #s = sin(pi*t)*exp(-...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Création d'un graphe 2D

On utilise la bibliothèque Pylab de matplotlib

from pylab import *

#t = arange(0.0, 2.01, 0.01)
#s = sin(pi*t)*exp(-t)
f = lambda x: sin(x*pi)
t = [ 0.01*i for i in range(201) ]
s = map(f,t)
plot(t, s)

xlabel('temps (s)')
ylabel('Tension (mV)')
title('Signal sinusoïdal')
grid(True)
show()

Il est en général plus simple de générer les tableaux avec numpy, la fonction plot utilisant la classe array

import numpy as np
from pylab import *

t = np.arange(0.0, 2.01, 0.01)
s = sin(pi*t)*exp(-t)
plot(t, s)

xlabel('temps (s)')
ylabel('Tension (mV)')
title('Signal sinusoïdal')
grid(True)
show()