From: Benjamin R. <ben...@ou...> - 2013-04-02 12:48:07
|
On Mon, Apr 1, 2013 at 3:51 PM, Michael Aye <mic...@uc...> wrote: > On 2013-04-01 13:45:07 +0000, Benjamin Root said: > > > > > On Fri, Mar 29, 2013 at 7:30 PM, Michael Aye > > <mic...@uc...> wrote: > > Is there a pylab version of ax.plot_surface? > > I am asking because the following does not work when running an ipython > > notebook in pylab mode: > > #0: #create some data …. > > #1: fig = plt.figure() > > ax = fig.gca(projection='3d') > > #2: surf = ax.plot_surface( …..) # taking the exact command from the > examples. > > > > I have verified that this code only does NOT work when #1 and #2 are > > executed in different notebook cells. When they are combined in the > > same cell, it works. > > As I prefer the flexibility of being able to run everything anywhere, I > > am asking for pylab versions of plot_surface, as I am mostly running > > things in the pylab mode of the notebook. > > > > Cheers, > > Michael > > > > > > The reason this does not work in separate cells is that a figure object > > gets closed at the end of a ipython cell. An ax object no longer works > > when its parent figure is closed. This is not limited to 3d plots. I > > would be surprised to see ax.plot() work if a non-3d axes object was > > made in a different cell. > > Sure, but isn't that just the reason why it doesn't work the OO-way? > That's exactly why I am asking for a pylab version of plot_surface that > does NOT require to have a 3d axes object available already. > > Huh? This has nothing to do with the OO approach to matplotlib. Ryan May did a tutorial last year on the OO approach to matplotlib using ipython notebooks. The issue at hand is that the pylab mode of ipython loads a special backend, IIRC, that "displays" the figure at the end of each cell. I have found that if the figure is empty, then nothing shows, but the figure is still destroyed. Without a figure object (implicit or otherwise), you can't display any new plots to the old axes regardless of the projection. So, what you really want is something that is not the pylab mode that doesn't try to do special stuff under the hood. Fernando and I have discussed various issues surrounding the ipython's pylab mode. I never did get around to submitting my patches (they wouldn't have helped in your case anyway), but I do wonder if they have made some progress in addressing this issue. I would suggest bringing this issue up with them (that the figure gets destroyed at the end of each cell). Ben Root |