How to Explore Multidimensional Datasets with Widgets#
This guide shows you how to use hvPlot’s automatic widget creation to interactively explore datasets with multiple dimensions. When you use the groupby parameter, hvPlot automatically creates widgets that let you drill-down into and explore your data dynamically.
Note
When viewing on a static website, the widgets will be inoperable. To explore this functionality fully, download the notebook and run it in a live python environment.
Basic Widget Creation with groupby#
When you use groupby, hvPlot automatically selects the appropriate widget type based on your data type. For categorical data like the ‘species’ column (composed of strings), hvPlot creates a drop-down menu (from a Panel Select widget). For numerical or datetime data, hvPlot creates slider widgets for smooth exploration.
import hvplot.pandas # noqa
penguins = hvplot.sampledata.penguins("pandas").dropna()
penguins.hvplot.scatter(
x='bill_length_mm',
y='bill_depth_mm',
groupby='species',
width=400
)
Widget Types for Different Data Types#
hvPlot automatically chooses the appropriate widget type based on your data:
Categorical/String data → Drop-down Select widget (as shown above)
Numerical data → DiscreteSlider widget (as shown below)
For numerical columns like year, hvPlot creates a slider widget that lets you explore different values from the different years.
import hvplot.pandas # noqa
penguins = hvplot.sampledata.penguins("pandas").dropna()
penguins.hvplot.scatter(
x='bill_length_mm',
y='bill_depth_mm',
groupby='year',
color='species',
width=400
)
Customizing Widget Placement#
You can control where the widget appears using the widget_location option. This is useful for creating layouts that work better with your specific visualization needs.
import hvplot.pandas # noqa
penguins = hvplot.sampledata.penguins("pandas").dropna()
penguins.hvplot.scatter(
x='bill_length_mm',
y='bill_depth_mm',
groupby='species',
widget_location='top_left'
)
Exploring Multiple Dimensions#
The penguins dataset has several categorical dimensions you can explore. We can group by multiple dimensions at once to explore different combinations of the data:
import hvplot.pandas # noqa
penguins = hvplot.sampledata.penguins("pandas").dropna()
# group by island and sex
penguins.hvplot.scatter(
x='flipper_length_mm',
y='body_mass_g',
groupby=['island', 'sex'],
color='species',
width=400,
)
Next Steps
For more advanced widget customization using Panel, see the Panel Widgets Reference
To understand the differences between
groupby,by, andcolorparameters, see the Grouping and Coloring Options Explanation