Snapshot from plotting.view_markers

Hi everybody,

I have been using nilearn’s plotting.view_markers() for plotting the location of SEEG electrodes and I very happy with it for interactive visualization. However I’d like to integrate these figures in an automatic pipeline and for this it lacks a method to automatically get a snapshot from the ViewConnectome object (basically doing the same as the “Download plot as a png” button in html, with a way to specify the view, opacity, …).

Is there an existing way to do this, or something similar? If not, do you think that it would be a worthy addition?
I know plotting.plot_connectome with an empty adjacency matrix would do the trick but I find the figures less good looking.

I realize my usage of this function is not canonical, but I think that this functionality would be generally useful.

Thanks in advance!

Hi, yes that would definitely be useful.

However I’m afraid it wouldn’t be very easy to do. The pages need to be opened
in a web browser to render the plots. Then, I believe the “download as a png”
cannot be done directly without user interaction for security reasons – a web
page cannot tell the browser to write in an arbitrary location in the
filesystem. So the easiest way to get the png may be to start a local server,
have the page upload the image to it and then have the server write the file.
Also closing the browser window afterwards (not the tabs) could be an issue.

Note that we wouldn’t have any problem if we were using the plotly python
interface but we don’t want to add this dependency to nilearn.

How were you thinking of implementing saving these plots in nilearn?

1 Like

I see. I did not realize the pages needed to be open but ofc it makes sense.

Maybe a simpler way to extract a high number of snapshots may be to use a jupyter notebook. Then you can render the html and iterate over the conditions you want. The only missing piece would be methods similar to mayavi.mlab.view and mayavi.mlab.screenshot, to automatically save the images.

Does it make sense?

unlike mayavi the plots are static web pages – there is no communication from the web browser that renders the plot to python. how were you thinking of implementing the equivalent of mlab.screenshot?

Ok so no way to get a snapshot from instructions… the problem is tougher than I though. I’ll think some about it.

Thanks a lot for the information!

you’re welcome! If you do think of something less messy than the solution outline above please let us know, as this would definitely be useful. good luck with your project!

1 Like