## matplotlib-users

 [Matplotlib-users] Newbie question about plotting multiple lines From: Ryugan Mizuta - 2004-09-08 09:53:02 Attachments: Message as HTML ```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```
 Re: [Matplotlib-users] Newbie question about plotting multiple lines From: Darren Dale - 2004-09-08 12:35:19 ```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) ```
 Re: [Matplotlib-users] Newbie question about plotting multiple lines From: John Hunter - 2004-09-08 14:04:39 ```>>>>> "Darren" == Darren Dale writes: Darren> There are a lot of ways to do this, I dont know them Darren> all. Here are a few to get you started: These are all good suggestions, and the right way 99% of the time. I just want to point out that if you need to plot hundreds or thousands of separate lines, calling plot over and over again is not the most efficient strategy, since a new matplotlib.lines.Line2D object must be created each time. For these cases it is best to use a line collection (matplotlib.collections.LineCollection). You can find an example of their use in the plotmap demo - http://matplotlib.sourceforge.net/screenshots.html#plotmap, where line collections are used to draw the geographic borders over a colormap. JDH ```
 Re[2]: [Matplotlib-users] Newbie question about plotting multiple lines From: Alan G Isaac - 2004-09-08 20:36:53 ```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) 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 ```