How to get interactive output from plot_surf_contours?

Hi everyone,

As it stands, I can plot surface results on fsaverage for some data I have, both in static form and in interactive form (by using engine='plotly' in the function nilearn.plotting.plot_surf_stat_map). I can also put some atlas surface contours over it using nilearn.plotting.plot_surf_contours). My results seem to be fixed and static and I can’t really see the effects nicely by not being able to zoom and navigate either in a Jupyter cell or in the browser.

I have to take engine='plotly' out of the figure creation for plot_surf_stat_map if I want to pass anything to plot_surf_contours but it seems I can include it in the latter function (but doesn’t seem to do anything so I think it’s just treated as a kwarg that can’t be matched and is ignored).

I can’t see how to get the interactive version of the first figure but now with ROI contours on it. Is there something that I can do with the plotting.view_image_on_surf function for this? I can’t see how to connect it all up.

I’ve been following this tutorial.

If I had a figure or something that was returned from plot_surf_contours I would have a play around but it only seems to have plotting.show() to call and display all active figures (i.e. plt.show())

The function plotting.view_surf is also nice and works, but again, doesn’t have the ROI boundaries and fails if I put this into the fig= parameter of plot_surf_contours.

Anyone have any idea how to get interactivity for this sort of plot? I’d even settle for the dropdown options view_surf gives to change orientation instead of full interactivity.

Code:

from nilearn import plotting

fig = plotting.plot_surf_stat_map(
    fsaverage.infl_left, sub29_results_fsaverage, hemi='left',
    title='Subject 29', colorbar=True, view='posterior',
    threshold=5.3, bg_map=curv_left_sign,
    engine='plotly', # works if just using this function
    bg_on_data=True
)

fig.show()

But what I was trying was the following, which doesn’t work:

fig = plotting.plot_surf_stat_map(
    fsaverage.infl_left, sub29_results_fsaverage, hemi='left',
    title='Subject 29', colorbar=True, view='posterior',
    threshold=5.3, bg_map=curv_left_sign,
    bg_on_data=True)

plotting.plot_surf_contours(fsaverage.infl_left, glasser, labels=labels,
                            levels=regions_indices, figure=fig,
                            legend=True, engine='plotly')
plotting.show()

I just get a static image with this. I don’t think providing the engine parameter to plot_surf_contours does anything (same thing happens if provided or not).

Anyone got any ideas? If not, perhaps a different way to manually mark ROI boundaries? Something like, put them on the bg_map directly in the plot_surf_stat_map or something?

  • Alex

I believe we have a pull request that is work in progress that should do what you want.

If you feel up to it, maybe you can test the proposed code and chime in on the pull request.

Also check the associated issue for more info.

I also spotted some functions that have some lazy kwargs like the one you mentioned: they accept extra parameters but don’t do anything with them.
Will try to clean those up in a future release to avoid this kind of confusion.

Hi Remi,

Long time no speak! Hope you’re doing well.
Thanks for linking the PR. I will definitely check that out and see how it all works. :grinning:

Alex

1 Like