Mayavi: scenes in Jupyter notebook are interleaved

Created on 26 Oct 2016  ·  10Comments  ·  Source: enthought/mayavi

When I plot one scene after another in my jupyter notebook with with x3d backend - this happens:
screen shot 2016-10-26 at 14 29 14

What should I do in order to prevent this? (I assume that you see the mesh from Out[2] in the center of the mesh in Out[8])

P.S. May be that's important - I'm running my jupyter notebook server on the remote machine under VirtualGL.

Most helpful comment

Hi all,

sorry for adding things to this closed issue but I thought this would be a good opportunity to give some feedback to the project.
I've just tested the jupyter notebook integration using x3d and got it to work after a few hiccups.
And I've felt the same than @thoth291 : I expected mayavi to create a new figure for a new cell implicitly. I guess I expected this because this is the default for matplotlib using the %matplotlib inline backend.
However, you could also argue for the opposite case: when using the %matplotlib notebook backend, one has to create figures explicitly (if not, the drawing action is perform with the previously opened figure, which sometimes yields surprising results for the user).

So to recap: different matplotlib backends behave differently with respect to new figure creation. From a user's point of view, it would easier if figures were tied to cells. However, if one follows the %matplotlib notebook suggestion, one could follow this workflow:

fig = mlab.figure() # create new figure
s = mlab.test_triangular_mesh() # draw something on it
fig # display figure

This actually works, so maybe something worthwhile would be to reformat the example notebook with this way of working, as well as the tips and tricks section which documents jupyter notebooks (http://docs.enthought.com/mayavi/mayavi/tips.html).

At any rate, I would like to add that I think it's great that this backend exists. Thank you for the hard work @prabhuramachandran @GaelVaroquaux !

Best regards,
Florian

All 10 comments

have you tried creating a new figure in the new cell?

I did this mlab.clf() in-between and it helped - no more interleaving.
Thanks @GaelVaroquaux !

Is it a bug or it's a feature? So should I clear the figure in all my scripts now?

@thoth291 -- This is the same as what you'd see without the notebook. mlab will not clear the screen automatically and you must do it yourself. BTW, I am curious about your setup with VirtualGL. What hardware are you using and how did you setup VirtualGL on a remote machine? This would be useful to others as well and perhaps we can add this to our documentation if you could share the details.

Am closing this issue for now as this is not an issue but how mlab works.

Unfortunately I'm not the one who did the setup.
All what I can say is that we are using HPC Intel machines with 60 cores, plenty of RAM and good GPU on board. We have multiple vnc servers running there. We user tigervnc and wen we start a server we set it up with VirtualGL backend. While you are in vnc client - you need to use a custom script to run you apps to intercept OpenGL and replace it with VirtualGL. In my case that script called vnc3d and I run it like this:

vnc3d jupyter notebook

This setup works perfectly for us and the only thing which is annoying is that you have to keep remember to prepend this vnc3d script to your command each time you deal with OpenGL...

@prabhuramachandran , I think this is counter intuitive for Jupyter users. Or at least it should be documented explicitly that one need to do it (mlab.clf()) to ensure correct rendering. None of the 3D engines (for Jupyter) I'm aware of having this kind of problem.

@prabhuramachandran , I think this is counter intuitive for Jupyter users.

I have the same feeling.

@thoth291 -- thanks for the information on the VirtualGL setup. That looks very interesting and useful. As regards the mlab.clf(), I am happy to document this although I am not sure it is confusing behavior. This is really quite similar to using mlab commands and then using mlab.savefig. You'd have the same effect. Perhaps what is confusing is that this is atypical from the perspective of notebook usage where users do plt.plot() in one cell and do not have to clf() before the next cell. What I can do is to automatically call mlab.clf() after the scene is converted to a PNG or X3D output cell? Would that help?

Yeah, that's the confusing part. May be it worth to put a new argument to init_notebook call when user can define what to do. I can imagine that many mlab users would be just fine having figures interleaving (so that they can gradually build a scene) - but the default behavior should be to have independent figures for each cell.

Hi all,

sorry for adding things to this closed issue but I thought this would be a good opportunity to give some feedback to the project.
I've just tested the jupyter notebook integration using x3d and got it to work after a few hiccups.
And I've felt the same than @thoth291 : I expected mayavi to create a new figure for a new cell implicitly. I guess I expected this because this is the default for matplotlib using the %matplotlib inline backend.
However, you could also argue for the opposite case: when using the %matplotlib notebook backend, one has to create figures explicitly (if not, the drawing action is perform with the previously opened figure, which sometimes yields surprising results for the user).

So to recap: different matplotlib backends behave differently with respect to new figure creation. From a user's point of view, it would easier if figures were tied to cells. However, if one follows the %matplotlib notebook suggestion, one could follow this workflow:

fig = mlab.figure() # create new figure
s = mlab.test_triangular_mesh() # draw something on it
fig # display figure

This actually works, so maybe something worthwhile would be to reformat the example notebook with this way of working, as well as the tips and tricks section which documents jupyter notebooks (http://docs.enthought.com/mayavi/mayavi/tips.html).

At any rate, I would like to add that I think it's great that this backend exists. Thank you for the hard work @prabhuramachandran @GaelVaroquaux !

Best regards,
Florian

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Ecauchy picture Ecauchy  ·  39Comments

yassersouri picture yassersouri  ·  5Comments

relyativist picture relyativist  ·  16Comments

Make42 picture Make42  ·  7Comments

rpep picture rpep  ·  7Comments