What about a "subplots" function ?

Hi again,

while browsing the docs about axes, I found this example, which seems to be a
recurrent "pattern" each time one wants to draw subplots in a figure:

cnt = 0
for i in range(numRows):
      for j in range(numCols):
           cnt+=1
           ax=subplot(numRows,numCols,cnt)
           plot(blah,blah)
           if ax.is_last_row() : xlabel('time(s)')
           if ax.is_first_col(): ylabel('volts')

Indeed, I've written such code many times now. It seems to me that the use of
subfigures could be make easier with such "subplots" function as:

for ax in subplots(numRows,numCols):
    plot(blah,blah)
    if ax.is_last_row() : xlabel('time(s)')
    if ax.is_first_col(): ylabel('volts')

What do you think ?

Hi,
using generators the fuction would go like this:
def subplots(numRows,numCols):
   cnt = 0
   for i in range(numRows):
      for j in range(numCols):
           cnt+=1
           ax=subplot(numRows,numCols,cnt)
           yield ax

right ?

- Sebastian

···

On Monday 13 June 2005 14:43, Nicolas Girard wrote:

Hi again,

while browsing the docs about axes, I found this example, which seems to be
a recurrent "pattern" each time one wants to draw subplots in a figure:

cnt = 0
for i in range(numRows):
      for j in range(numCols):
           cnt+=1
           ax=subplot(numRows,numCols,cnt)
           plot(blah,blah)
           if ax.is_last_row() : xlabel('time(s)')
           if ax.is_first_col(): ylabel('volts')

Indeed, I've written such code many times now. It seems to me that the use
of subfigures could be make easier with such "subplots" function as:

for ax in subplots(numRows,numCols):
    plot(blah,blah)
    if ax.is_last_row() : xlabel('time(s)')
    if ax.is_first_col(): ylabel('volts')

What do you think ?

-------------------------------------------------------
This SF.Net email is sponsored by: NEC IT Guy Games. How far can you
shotput a projector? How fast can you ride your desk chair down the office
luge track? If you want to score the big prize, get to know the little guy.
Play to win an NEC 61" plasma display: necitguy.com - This website is for sale! - necitguy Resources and Information.
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Yes, exactly. I'd be interested in
having your opinion on the convenience of this vs the standard use of
subplot()...

cheers,
nicolas

···

On Tuesday 14 June 2005 00:56, Sebastian Haase wrote:

Hi,
using generators the fuction would go like this:
def subplots(numRows,numCols):
   cnt = 0
   for i in range(numRows):
      for j in range(numCols):
           cnt+=1
           ax=subplot(numRows,numCols,cnt)
           yield ax

right ?

- Sebastian