Skip to content

Integrate better with Jupyter notebook #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,17 @@ notebook), you have to activate the correct GUI backend, which is probably qt::
This will allow you to have an open PySurfer window while still being able to
execute code in the console/notebook.

It is also possible to embed the PySurfer visualization into a Jupyter notebook.
This is achieved by leveraging `Mayavi's notebook integration
<https://docs.enthought.com/mayavi/mayavi/tips.html#using-mayavi-in-jupyter-notebooks>`_::

from mayavi import mlab
mlab.init_notebook(backend='png')

The ``backend`` parameter can either be ``'png'`` to render the visualization
as a static PNG image, or ``'x3d'`` to render it using
`X3D <https://www.x3dom.org>`_ (still experimental).

If you are having trouble getting started using PySurfer, please describe the problem on the `nipy mailing list`_.

.. include:: links_names.txt
Expand Down
17 changes: 17 additions & 0 deletions surfer/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2776,6 +2776,23 @@ def animate(self, views, n_steps=180., fname=None, use_cache=False,
if ret:
print("\n\nError occured when exporting movie\n\n")

def __repr__(self):
return ('<Brain subject_id="%s", hemi="%s", surf="%s">' %
(self.subject_id, self._hemi, self.surf))

def _ipython_display_(self):
"""Called by Jupyter notebook to display a brain."""
from IPython.display import display as idisplay

if mlab.options.offscreen:
# Render the mayavi scenes to the notebook
for figure in self._figures:
for scene in figure:
idisplay(scene.scene)
else:
# Render string representation
print(repr(self))


def _scale_sequential_lut(lut_table, fmin, fmid, fmax):
"""Scale a sequential colormap."""
Expand Down