Come posso tracciare i seguenti 3 funzioni (ad esempio sin
, cos
e l'aggiunta), sul dominio t
, nella stessa figura?
from numpy import *
import math
import matplotlib.pyplot as plt
t = linspace(0, 2*math.pi, 400)
a = sin(t)
b = cos(t)
c = a + b
Come posso tracciare i seguenti 3 funzioni (ad esempio sin
, cos
e l'aggiunta), sul dominio t
, nella stessa figura?
from numpy import *
import math
import matplotlib.pyplot as plt
t = linspace(0, 2*math.pi, 400)
a = sin(t)
b = cos(t)
c = a + b
Risposte:
Per tracciare più grafici sulla stessa figura dovrai fare:
from numpy import *
import math
import matplotlib.pyplot as plt
t = linspace(0, 2*math.pi, 400)
a = sin(t)
b = cos(t)
c = a + b
plt.plot(t, a, 'r') # plotting t, a separately
plt.plot(t, b, 'b') # plotting t, b separately
plt.plot(t, c, 'g') # plotting t, c separately
plt.show()
plt.show()
quindi la stampa di nuovo non verrà tracciata sullo stesso grafico.
Forse un modo più pitonico per farlo.
from numpy import *
import math
import matplotlib.pyplot as plt
t = linspace(0,2*math.pi,400)
a = sin(t)
b = cos(t)
c = a + b
plt.plot(t, a, t, b, t, c)
plt.show()
plt.plot()
parte come: plt.plot(t, a, 'b', t, b, 'g', t, c, 'y')
. Puoi specificare i colori in base ai colori forniti in questo link: matplotlib.org/users/colors.html
ion()
in pyplot anche per questo, piuttosto che tracciare tutto in una singola riga?
ion()
. Puoi illustrare con un esempio?