How to Lay Out Plots#

This guide shows you how to display several hvPlot plots side by side or in a grid with the + operator.

import holoviews as hv
import hvplot.pandas  # noqa

penguins = hvplot.sampledata.penguins("pandas")
bill_plot = penguins.hvplot.scatter(
    x='bill_length_mm', y='bill_depth_mm', by='species', width=400, height=300
)
length_plot = penguins.hvplot.hist('bill_length_mm', width=400, height=300)
flipper_plot = penguins.hvplot.box(
    y='flipper_length_mm', by='species', width=400, height=300
)
mass_plot = penguins.hvplot.scatter(
    x='flipper_length_mm', y='body_mass_g', width=400, height=300
)

Place plots side by side#

Add plots with + to get a layout. Plots are laid out in a row and wrap onto new lines depending on the available width.

bill_plot + length_plot

Set the number of columns#

Use .cols() to control how many plots are on each row.

(bill_plot + length_plot + flipper_plot + mass_plot).cols(2)

Build a layout from a list#

When the number of plots is not fixed, build them in a list and pass it to hv.Layout. Calling .cols() on it works the same as before.

columns = ['bill_length_mm', 'bill_depth_mm', 'flipper_length_mm', 'body_mass_g']
plots = [penguins.hvplot.hist(col, width=400, height=300) for col in columns]
hv.Layout(plots).cols(2)

Make plots independent#

Plots in a layout share their axes when they share dimension names. Here bill_plot and length_plot share the bill_length_mm axis, so zooming or panning one plot updates the other. Disable this with shared_axes=False.

(bill_plot + length_plot).opts(shared_axes=False)

Next Steps

This web page was generated from a Jupyter notebook and not all interactivity will work on this website.