using subplot to plot a large numbers of graphs in a loop

You seem to be mixing idioms, between pylab which manages current
figure and current axes, and explicitly managing the Figure and Axes
instances yourself. Eg

  fig = figure()
  hold(False) #<-- manipulates current axes
  for counter in counter_list:
    y = intensities_calc[counter]
    plotnr = plotnr+1
    ax = subplot(rownrs, colnrs, plotnr) #<-- uses current fig
    fig.add_subplot(ax)
    plot(x,y) #<-- uses current axes
    if ax.is_last_row():
    ax.set_xlabel('time')

If you want to manage the figure and axes attributes yourself, which
is good practice, I suggest imposing some discipline on yourself and
only importing 4 things from pylab (this is what I usually do)

  from pylab import figure, show, nx, close

Your code would then look something like:

    fig = figure()
    for counter in counter_list:
        y = intensities_calc[counter]
        plotnr = plotnr+1
        ax = fig.add_subplot(rownrs, colnrs, plotnr)
        ax.hold(False)
        ax.plot(x,y)
        if ax.is_last_row():
            ax.set_xlabel('time')

That should work, as long as plotnr is incrementing like you expect it
to.

JDH

Here is an example that works for me doing this as John mentioned
(figure 2) or the first way that came to my mind (figure 1):

from numpy import zeros, arange, sin, cos, pi
from pylab import figure, subplot, plot, show, cla, clf
t=arange(0,1,0.01)
y=zeros([len(t),4],'d')
y[:,0]=sin(2*pi*t)
y[:,1]=cos(2*pi*t)
y[:,2]=sin(2*pi*t*2+1)
y[:,3]=cos(2*pi*t*2+1)

nc=1
nr=4

figure(1)
clf()
for x in range(nr):
    subplot(nr,1,x+1)
    plot(t,y[:,x])

figure(2)
clf()
for x in range(nr):
    ax = figure(2).add_subplot(nr, 1, x+1)
    ax.hold(False)
    ax.plot(t,y[:,x])
    if ax.is_last_row():
        ax.set_xlabel('time')

show()

···

On 4/17/06, John Hunter <jdhunter@...4...> wrote:

You seem to be mixing idioms, between pylab which manages current
figure and current axes, and explicitly managing the Figure and Axes
instances yourself. Eg

        fig = figure()
        hold(False) #<-- manipulates current axes
        for counter in counter_list:
                y = intensities_calc[counter]
                plotnr = plotnr+1
                ax = subplot(rownrs, colnrs, plotnr) #<-- uses current fig
                fig.add_subplot(ax)
                plot(x,y) #<-- uses current axes
                if ax.is_last_row():
                ax.set_xlabel('time')

If you want to manage the figure and axes attributes yourself, which
is good practice, I suggest imposing some discipline on yourself and
only importing 4 things from pylab (this is what I usually do)

  from pylab import figure, show, nx, close

Your code would then look something like:

    fig = figure()
    for counter in counter_list:
        y = intensities_calc[counter]
        plotnr = plotnr+1
        ax = fig.add_subplot(rownrs, colnrs, plotnr)
        ax.hold(False)
        ax.plot(x,y)
        if ax.is_last_row():
            ax.set_xlabel('time')

That should work, as long as plotnr is incrementing like you expect it
to.

JDH

-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Jakob,

Here's an example of managing axes, etc yourself while plotting. John covered just about everything I was going to mention in his email, but I'd like to add that using "from XYZ import *" in scripts can make them hard for other people to understand.

Ken

import pylab

nrows = 2
ncols = 3
x = pylab.arange(0, 10, 0.1) # your X here

fig = pylab.figure()
for i in range(0, nrows*ncols):
     y = i * x # your Y here
     # i goes 0..N-1, but the plot number goes 0..N, so add one here
     ax = fig.add_subplot(nrows, ncols, i+1)
     ax.plot(x, y)
     if ax.is_last_row():
         ax.set_xlabel('time')

pylab.show()

Thanks John & Ryan,

I'm sitting here in Germany, Berlin, trying to get some data-analysis
up to par during the Easter holidays and can't get over the fact that
I'm getting help from around the globe, within minutes.

It seems to work now!

Jakob

···

On 4/17/06, Ryan Krauss <ryanlists@...287...> wrote:

Here is an example that works for me doing this as John mentioned
(figure 2) or the first way that came to my mind (figure 1):

from numpy import zeros, arange, sin, cos, pi
from pylab import figure, subplot, plot, show, cla, clf
t=arange(0,1,0.01)
y=zeros([len(t),4],'d')
y[:,0]=sin(2*pi*t)
y[:,1]=cos(2*pi*t)
y[:,2]=sin(2*pi*t*2+1)
y[:,3]=cos(2*pi*t*2+1)

nc=1
nr=4

figure(1)
clf()
for x in range(nr):
    subplot(nr,1,x+1)
    plot(t,y[:,x])

figure(2)
clf()
for x in range(nr):
    ax = figure(2).add_subplot(nr, 1, x+1)
    ax.hold(False)
    ax.plot(t,y[:,x])
    if ax.is_last_row():
        ax.set_xlabel('time')

show()

On 4/17/06, John Hunter <jdhunter@...4...> wrote:
>
> You seem to be mixing idioms, between pylab which manages current
> figure and current axes, and explicitly managing the Figure and Axes
> instances yourself. Eg
>
> fig = figure()
> hold(False) #<-- manipulates current axes
> for counter in counter_list:
> y = intensities_calc[counter]
> plotnr = plotnr+1
> ax = subplot(rownrs, colnrs, plotnr) #<-- uses current fig
> fig.add_subplot(ax)
> plot(x,y) #<-- uses current axes
> if ax.is_last_row():
> ax.set_xlabel('time')
>
> If you want to manage the figure and axes attributes yourself, which
> is good practice, I suggest imposing some discipline on yourself and
> only importing 4 things from pylab (this is what I usually do)
>
> from pylab import figure, show, nx, close
>
> Your code would then look something like:
>
> fig = figure()
> for counter in counter_list:
> y = intensities_calc[counter]
> plotnr = plotnr+1
> ax = fig.add_subplot(rownrs, colnrs, plotnr)
> ax.hold(False)
> ax.plot(x,y)
> if ax.is_last_row():
> ax.set_xlabel('time')
>
> That should work, as long as plotnr is incrementing like you expect it
> to.
>
> JDH
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by xPML, a groundbreaking scripting language
> that extends applications into web and mobile media. Attend the live webcast
> and join the prime developer group breaking into this new coding territory!
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
> matplotlib-users List Signup and Options
>

--
Jakob J. Lopez (JakobJLopez@...287...)