Courbe représentative d'une fonction

Le minimum

In [3]:
from pylab import plt,linspace,show

x = linspace(-3, 5, 50)
y = x**2+3
plt.plot(x, y)
show()

Mieux :

In [4]:
from pylab import *
x = linspace(-3, 5, 50)
y = x**2+3
plot(x, y, label="f")
legend()
xlim(-3, 5)
ylim(-1, 10)
xlabel("abscisses")
ylabel("ordonnees")
title("TITRE")
show()

Avec des axes se coupant en (0,0) et calcul de la meilleure fenêtre

In [5]:
from pylab import *

x = linspace(-3, 5, 50)
y1 = x**2-3
y2= x**2 -2*x+2
plot(x, y1, label="f")
plot(x, y2, "r--",label="g")
legend()
xlim(-3, 5)
#ylim(-1, 10)
xlabel("abscisses")
ylabel("ordonnees")
title("Fonctions du second degre")
grid(True) #grille
setp(gca(),autoscale_on=True) #calcul de la meilleure fenêtre
#pour avoir des axes se coupant en (0,0)
ax = gca()  #gca() retourne les axes courants
ax.spines['right'].set_color('none')
ax.spines['top'].set_color('none')
ax.xaxis.set_ticks_position('bottom')
ax.spines['bottom'].set_position(('data',0))
ax.yaxis.set_ticks_position('left')
ax.spines['left'].set_position(('data',0))

show()

Plusieurs figures :

In [6]:
from pylab import *
#definition d'une fonction du seconde degre f(x)=ax**2+bx+c
def f(a,b,c,x):
    return a*x**2+b*x+c

x = linspace(-5, 5, 50)
y1 = f(1,2,-3,x)
y2 = f(1,2,1,x)
y3 = f(1,2,3,x)
y4 = f(-1,-2,3,x)
y5 = f(-1,-2,-1,x)
y6 = f(-1,-2,-3,x)

figure(figsize=(10,6),dpi=80)

subplot(231)  #2  lignes , 3 colonnes 1ère figure
plot(x, y1, label="f1")
legend()
grid(True)

subplot(232)
plot(x, y2,'r-', label="f2")
legend()
grid(True)

subplot(233)
plot(x, y3, 'g-',label="f3")
legend()
grid(True)

subplot(234)
plot(x, y4, 'y-',label="f4")
legend()
grid(True)

subplot(235)
plot(x, y5, 'c-',label="f5")
legend()
grid(True)

subplot(236)
plot(x, y6, 'k-',label="f6")
legend()
grid(True)

show()

Représentation graphique de suite

Tracé point par point

In [7]:
from pylab import *
#suite u(n) définie par u(0)=2 et u(n+1)=0.8*u(n)-3
u=2
xlim(0,5)
grid(True)
for n in range(6):
    plot(n,u,'ro')
    u=0.8*u-3
show()
In [ ]:
Avec une liste
In [8]:
from pylab import *
#suite u(n) définie par u(0)=2 et u(n+1)=0.8*u(n)-3
u=[2,0,0,0,0,0]
for n in range(5):
    u[n+1]=0.8*u[n]-3
xlim(0,5)
plot(u,'ro')
grid(True)
show()
In [ ]: