Matplotlib: graphe 2D: Difference between revisions

From Wiki Cours
Jump to navigation Jump to search
(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(-...")
 
Line 5: Line 5:
from pylab import *
from pylab import *


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

Revision as of 10:41, 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 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()