Skip to content

Interactive Graphics

Gary Pavlis edited this page Jun 19, 2023 · 2 revisions

Motivation

For efficiency standard graphics displays in a jupyter notebook or jupyterlab output are not interactive. That is, they are plotted and the python code continues execution. In a batch mode with HPC that is the only rational way to do any graphics, but when exploring data that may not always be desirable. A case in point is long time series where one might want to understand the form of a set of spikes or other warts in data as part of developing a prototype workflow. Then the zoom and pan features of standard matplotlib graphics are essential. This page describes how you can do that easily with MsPASS graphics that are based on matplotlib.

We emphasize one should NEVER enable the features below in a notebook that is to be run as a batch script. The interactive gizmos will spawn separate threads to handle the interactive graphics with unpredictable results in a batch run on an HPC system. At best it would create an efficiency. At worst, it could theoretically cause thread deadlocks.

jupyterlab

When running MsPASS in the containerized form (i.e. run with docker or singularity) since spring 2023 MsPASS uses jupyterlab as the front end. The way to enable interactive graphics in jupyterlab turns out to be different from jupyter notebook. For jupyter lab at an appropriate place in your notebook create a separate box containing this incanation:

%matplotlib widget

jupyter notebook

If you are using the older jupyter notebook interface, which can be appropriate running with a locally installed, not containerized copy of MsPASS, the incantation is different. Use:

%matplotlib notebook

Disabling interactivity

At an appropriate place in your workbook we also recommend you also create a code box with this incanation:

%matplotlib inline

That disables interactive graphics after it is executed. That command, at least, is the same for jupyter lab and jupyter notebook.

What is "appropriate" depends on how you are using the notebook. If you are always executing it from the top down insert it where you want to switch. If you are jumping around, which is common in prototyping, you can put it anywhere and run either box like and on/off switch as needed.

Finally, a practical issue I (glp) have seen. It seems to be a bad idea to run a notebook with a number of different figures all having interactive widgets running. It seems to confuse the notebook server and I have seen the wrong graphic displayed in a box that behaves normally when run in normal run mode.