On Feb 18, 2008 2:00 PM, John Hunter <[EMAIL PROTECTED]> wrote:
> You will need to remove the axes from the original figure:
>
>   oldfig.delaxes(ax)
>
>
> and then add it to the new figure
>
>   ax.set_figure(newfig)
>   newfig.add_axes(ax)
>
> If you are adding several, you may want to play with the axes position
> or geometry (for subplots) ax.set_position and ax.change_geometry
>
> And yes, the data, titles, labels, grids, ticks, etc will be brought
> over.  As Eric points out, this is an under-exercised part of the code
> so something may break, though last time I tried it it worked.

Thanks, that allowed me to make some real progress, and worked to some
degree. Here is the code I am using:

figs = [x[0] for x in results]
oldaxs = [fig.get_children()[1] for fig in figs]
for fig, ax in zip(figs,oldaxs):
   fig.delaxes(ax)
   pl.close(fig)

newf = pl.figure()

for i,ax in enumerate(oldaxs):
   ax.set_figure(newf)
   newf.add_axes(ax)
   ax.change_geometry(2,2,i+1)

pl.show()

Unfortunately, there are some problems:
- while the subplots are correct, they don't resize when I resize the window
- the plots are bar graphs, only the first xtick label is there, the
others are missing
- top of the xaxis of the bottom row of plots overlaps with the bottom
of the x axis of the top row - generally it looks pretty bad

Since this approach is proving problematic, and sounds like it isn't
really supported anyway (I had imagined it would be relatively
straightforward) I think it would be better to try the other way
(passing optional axes argument to plot to if I want it in a
multi-subplot figure, otherwise just create a new figure). I would
appreciate some pointers on how to do this. ie:

fig = plot_data1(data1) # this should create a new figure obect and return it

newfig = figure()
sp1 = subplot(221)
plot_data1(data1, axes=sp1) # this should plot the data on the
provided subplot axes.

However I do not know how to make the bar, title, xlabel, xtick etc.
commands I am using from pylab within the function act on the
specified subplot axes (if present).
Is this possible?

Thanks,

Robin

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to