Matplotlib: graphe 2D: Difference between revisions

From Wiki Cours
Jump to navigation Jump to search
Line 1: Line 1:
== Création d'un graphe 2D ==
== Création d'un graphe 2D ==
<math> \sum_i a_i</math>


On utilise la bibliothèque '''Pylab''' de '''matplotlib'''
On utilise la bibliothèque '''Pylab''' de '''matplotlib'''

Revision as of 14:36, 16 July 2015

Création d'un graphe 2D

On utilise la bibliothèque Pylab de matplotlib

from pylab import *

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 sinusoidal')
grid(True)
show()

Il est en général plus simple de générer les tableaux avec la classe array qui est importée par pylab

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 sinusoidal')
grid(True)
show()