import panel as pn
import hvplot.pandas
from bokeh.sampledata.autompg import autompg_clean
pn.extension()
This example demonstrates how to combine multiple columns of widgets into layout an overall layout.
quant = [None, 'mpg', 'cyl', 'displ', 'hp', 'weight', 'yr']
cat = [None, 'origin', 'mfr', 'yr']
combined = quant+cat[1:]
x = pn.widgets.Select(name='x', value='mpg', options=combined)
y = pn.widgets.Select(name='y', value='cyl', options=combined)
color = pn.widgets.Select(name='color', options=combined)
facet = pn.widgets.Select(name='facet', options=cat)
@pn.depends(x, y, color, facet)
def plot(x, y, color, facet):
cmap = 'Category10' if color in cat else 'viridis'
return autompg_clean.hvplot.scatter(
x, y, color=color or 'darkblue', by=facet, subplots=True, padding=0.1,
cmap=cmap, responsive=True, min_height=300
)
pn.Column(
'### Auto MPG Explorer',
plot,
pn.Row(pn.WidgetBox(x, y, color), pn.WidgetBox(facet)),
width_policy='max'
).servable()