I'm using matplotlib in OO mode.
I created an instance of Figure then add some subplots to it.
from matplotlib.axes import Subplot
from matplotlib.figure import Figure
self.fig = Figure(figsize=(320,200), dpi=80)
a = self.fig.add_subplot(1,1,1, axisbg='r')
Now i create another instance of Figure.
self.new_fig = Figure(figsize=(320,200), dpi=80)
My aim is to add a Subplot instance to the new Figure instance and
changind the number of rows and columns and the position of the Subplot.
I could have done:
Nevertheless, it doesn't work. self.new_fig is empty when displaying it
in a FigureCanvas.
Furthermore, i need the property of subplot to change.
Is there any solution except to make another instance of the subplot?
Thanks a lot,
From: John Hunter <jdhunter@ac...> - 2005-09-24 19:25:14
phil> I created an instance of Figure then add
phil> some subplots to it.
phil> Now i create another instance of Figure.
phil> self.new_fig = Figure(figsize=(320,200),
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
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
and call it like
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.