plot_surface in pylab mode?

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.

···

On 2013-04-01 13:45:07 +0000, Benjamin Root said:

On Fri, Mar 29, 2013 at 7:30 PM, Michael Aye > <michael.aye@...2722...> wrote:

Ben Root

------------------------------------------------------------------------------
Own the Future-Intel&reg; Level Up Game Demo Contest 2013
Rise to greatness in Intel's independent game demo contest.
Compete for recognition, cash, and the chance to get your game
on Steam. $5K grand prize plus 10 genre and skill prizes.
Submit your demo by 6/6/13. http://p.sf.net/sfu/intel_levelupd2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

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

···

On Mon, Apr 1, 2013 at 3:51 PM, Michael Aye <michael.aye@...2722...> wrote:

On 2013-04-01 13:45:07 +0000, Benjamin Root said:

>
> On Fri, Mar 29, 2013 at 7:30 PM, Michael Aye > > <michael.aye@...2722...> 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.

2013/4/2 Benjamin Root <ben.root@…1304…>:

I would suggest bringing this issue up with them (that the figure
gets destroyed at the end of each cell).

The default behaviour of the inline backend is closing figures after cell execution, but this is configurable[1]

That said you should be able to use the OO approach with oneliners like this:

surf = plt.gca(projection=‘3d’).plot_surface(…)

Or write you own pyplot-style function. Adding 3d plotting functions to pyplot might or might not be a good thing, I can’t tell. Or there might be a separate, pyplot-like module for 3d. Does that make sense?

http://ipython.org/ipython-doc/stable/interactive/qtconsole.html#pylab-inline

Goyo