subplots with the OO interface (ax.rowNum, ax.colNum)

I have a figure with 2 subplots (2 rows, 1 column) created using the
OO interface like this:

ax1=fig.add_subplot(2,1,1)
ax2=fig.add_subplot(2,1,2)

After I have created these axes and plotted things on them, I want to
be able to set their x and y lims. The function that creates the plot
returns fig. I can then get to a list of the axes from fig.axes. My
question is this: can I know from the list of axes or their individual
properties which one is which - i.e. which one is the top one and
which one is the bottom one? It looks like ax1.rowNum and colNum
should refer to the parameters I want (rowNum in this case, since
there is only one column). But there isn't a docstring for them. Is
this there intended use (or at least a safe use of them)?

99% of the time, I will create the top one first so topfig=fig.axes[0]
and bottomfig=fig.axes[1]. But if I ever screw that up, it could be
bad.

Thanks,

Ryan

If you are creating subplots, you can do

rows, cols, num = ax.get_geometry()

You can also change the geometry with set_geometry.

There are a couple of Subplot helper functions you may find useful, eg
to selectively apply x and ylabeling:

    def is_first_col(self):
        return self.colNum==0

    def is_first_row(self):
        return self.rowNum==0

    def is_last_row(self):
        return self.rowNum==self.numRows-1

    def is_last_col(self):
        return self.colNum==self.numCols-1

···

On 3/20/07, Ryan Krauss <ryanlists@...287...> wrote:

I have a figure with 2 subplots (2 rows, 1 column) created using the
OO interface like this:

ax1=fig.add_subplot(2,1,1)
ax2=fig.add_subplot(2,1,2)

After I have created these axes and plotted things on them, I want to
be able to set their x and y lims. The function that creates the plot
returns fig. I can then get to a list of the axes from fig.axes. My
question is this: can I know from the list of axes or their individual
properties which one is which - i.e. which one is the top one and
which one is the bottom one? It looks like ax1.rowNum and colNum
should refer to the parameters I want (rowNum in this case, since
there is only one column). But there isn't a docstring for them. Is
this there intended use (or at least a safe use of them)?

99% of the time, I will create the top one first so topfig=fig.axes[0]
and bottomfig=fig.axes[1]. But if I ever screw that up, it could be
bad.

Thanks John. That will work.

Ryan

···

On 3/20/07, John Hunter <jdh2358@...287...> wrote:

On 3/20/07, Ryan Krauss <ryanlists@...287...> wrote:
> I have a figure with 2 subplots (2 rows, 1 column) created using the
> OO interface like this:
>
> ax1=fig.add_subplot(2,1,1)
> ax2=fig.add_subplot(2,1,2)
>
> After I have created these axes and plotted things on them, I want to
> be able to set their x and y lims. The function that creates the plot
> returns fig. I can then get to a list of the axes from fig.axes. My
> question is this: can I know from the list of axes or their individual
> properties which one is which - i.e. which one is the top one and
> which one is the bottom one? It looks like ax1.rowNum and colNum
> should refer to the parameters I want (rowNum in this case, since
> there is only one column). But there isn't a docstring for them. Is
> this there intended use (or at least a safe use of them)?
>
> 99% of the time, I will create the top one first so topfig=fig.axes[0]
> and bottomfig=fig.axes[1]. But if I ever screw that up, it could be
> bad.

If you are creating subplots, you can do

rows, cols, num = ax.get_geometry()

You can also change the geometry with set_geometry.

There are a couple of Subplot helper functions you may find useful, eg
to selectively apply x and ylabeling:

    def is_first_col(self):
        return self.colNum==0

    def is_first_row(self):
        return self.rowNum==0

    def is_last_row(self):
        return self.rowNum==self.numRows-1

    def is_last_col(self):
        return self.colNum==self.numCols-1