# Newbie question about plotting multiple lines

Hi all,

I’m trying to create multiple lines on one graph. Anybody have an idea of plotiing multiple lines without writing the plot statement a number of times? Is it possible to include the plot statement inside a “for” statement to produce multiple lines in one graph???

Thanks.

Ryugan

Ryugan Mizuta wrote:

Hi all,
I'm trying to create multiple lines on one graph. Anybody have an idea of plotiing multiple lines without writing the plot statement a number of times? Is it possible to include the plot statement inside a "for" statement to produce multiple lines in one graph???

Hi Ryugan,

There are a lot of ways to do this, I dont know them all. Here are a few to get you started:

from matplotlib.matlab import *

a=arange(10)
b=a*2
c=a*3
figure(1)
plot(a,b,a,c)
figure(2)
plot(a,b,'k',a,c,'r')

figure(3)
[plot(a,i) for i in [b,c]]
#equivalent to:
figure(4)
for i in [b,c]:
plot(a,i)

These two examples suggest that one
ought to be able to input 2D arrays
for plotting against a 1D array.
(As in, e.g., GAUSS's xy() command.)

fwiw,
Alan Isaac

···

On Wed, 08 Sep 2004, Darren Dale apparently wrote:

from matplotlib.matlab import *
figure(3)
[plot(a,i) for i in [b,c]]
#equivalent to:
figure(4)
for i in [b,c]:
plot(a,i)