Interactive Pipelines#

The plots built up over the first few tutorials were all highly interactive in the web browser, with interactivity provided by Bokeh plotting tools within the plots or in some cases by HoloViews generating a Bokeh widget to select for a groupby over a categorical variable. However, when you are exploring a dataset, you might want to see how any aspect of the data or plot changes if varied interactively. Luckily, hvPlot makes it almost trivially easy to do this, so that you can very easily explore any parameter or setting in your code.

Panel widgets#

To do this, we will need a widget library, and here we will be using Panel to generate Bokeh widgets under user control, just as hvPlot uses Panel to generate widgets for a groupby as shown previously. Let’s first get ahold of a Panel widget to see how they work. Here, let’s create a Panel floating-point number slider to specify an earthquake magnitude between zero and nine:

import panel as pn

mag_slider = pn.widgets.FloatSlider(name='Minimum Magnitude', start=0, end=9, value=6)

The widget is a JavaScript object, but there are bidirectional connections between JS and Python that let us see and change the value of this slider using its value parameter:

mag_slider.value = 7


Try moving the slider around and rerunning the mag_slider.value above to access the current slider value. As you can see, you can easily get the value of any widget to use in subsequent cells, but you’d need to re-run any cell that accesses that value for it to get updated.

hvPlot .interactive()#

hvPlot provides an easy way to connect widgets directly into an expression you want to control.

First, let’s read in our data:

import pathlib
import numpy as np
import pandas as pd
import holoviews as hv
import hvplot.pandas # noqa