phil> I created an instance of Figure then add
phil> some subplots to it.
...snip
phil> Now i create another instance of Figure.
phil> self.new_fig = Figure(figsize=(320,200),
phil> dpi=80)
phil> My aim is to add a Subplot instance to the
phil> new Figure instance and changind the
phil> number of rows and columns and the
phil> position of the Subplot. I could have
phil> done: self.new_fig.add_subplot(a)
The important thing to understand is that there is no concept of
"number of rows" of a figure, or "number of columns". The Subplot is
an instance of an Axes, and an Axes has a position property. The
position is left, bottom, width, height in fractional (0,1)
coordinates. When you say Subplot(111), matplotlib computes the
position but the figure does not have the property that it has one row
and one column. For example, you could do
ax1 = subplot(111)
ax2 = axes([0.8, 0.8, 0.15, 0.15])
and have another axes over the subplot. How many rows and columns
does the figure have? It's not particularly well defined, since it
has two axes, but not on a regular grid. Each figure maintains a list
of axes, and you can move them from one to another, and you can manage
their sizes in figure they live in with ax.get_position() and
ax.set_position()
fig1.delaxes(ax1)
ax1.set_position(something)
ax2.set_position(something_else)
fig2.add_axes(ax1)
If you want to set the position for a given subplot geometry (eg 211)
you can add the following method to axes.Subplot
def change_geometry(self, numrows, numcols, num):
'change subplot geometry, eg from 1,1,1 to 2,2,3'
self._rows = rows
self._cols = cols
self._num = num
self.update_params()
and call it like
ax2.change_geometry(2,2,3)
You may want to make sure each axes instance you create has an unique
"label". The "current axes" machinery works by comaring the args and
kwargs you pass to add_axes. This is documented with an example in
the Figure.add_axes method.
JDH
