I'm not sure I understand what you want to do; is it to recycle axes
objects that were originally in one or more figures and put them in
I have a number of figures created from functions like this:
fig1 = plot_fig1(data1)
fig2 = plot_fig2(data2)
Now instead of having two separate figure windows displaying the
plots, I would like them to appear as subplots in a new figure (single
window) and close the previous figures. Other than moving to the
subplot in a new figure, I would like everything about the plot to
remain the same (titles, labels, scale,ticks etc.)
I had imagined something like this would be possible:
newfig = figure()
sp1 = subplot(211)
for x in fig1.get_children():
or similar, but it doesn't seem to work. Also, when trying something
like this, does it matter if the original figure windows are already
closed? (ie does the act of closing the window change the objects to
make them not show-able any more).
I'm not sure if I can do this reallocation by figure or axes, that is
what I was asking really.
It looks like that might be doable if you create the
new figure, then for each axes call ax.set_figure(newfig), and then for
each axes call newfig.add_axes(ax). I would be not the least surprised
if all this failed, though.
If I move the axes over as you describe, will this also bring the
plotted data, titles etc.? I will try and play around with this later
today. Would I first have to delete the existing axes created when I
create the subplot? Wouldn't that make a problem, since isn't it these
created axis that have the important subplot position properties (if I
just move over the existing axes how will the subplot placing work).
I imagine I might have to, copy over the axes from old figure, set
position and size of old axes to those of new subplot axes, copy over
all children (rectangles, text etc.)?
Alternatively if theres another way of achieving the same thing. I
thought I could modify the functions to take an optional axes
argument, so if not present they make a new figure, and if present
they use that:
fig = figure()
sp1 = subplot(211)
but then I'm not sure how inside the function, I use plot commands
(bar, plot, imshow) on this provided subplot axis.
On Feb 18, 2008 4:44 AM, Eric Firing <efiring@...202...> wrote: