How to Split a Plot into Subplots#

This guide shows you how to split a plot into subplots (also called facets), one per column or per group, instead of overlaying everything on a single set of axes.

import hvplot.pandas  # noqa

stocks = hvplot.sampledata.stocks("pandas")
penguins = hvplot.sampledata.penguins("pandas")

Split wide data into subplots#

When your data is wide, with one column per series like the stocks below, hvPlot overlays the columns on the same axes by default. Set subplots=True to draw each column in its own plot. Use .cols() to set the number of plots per row, as shown in Lay out plots.

stocks.hvplot(
    x='date', y=['Apple', 'Google', 'Meta'], value_label='Stock Price',
    subplots=True, width=250, height=200,
).cols(3)

Note

When y is not set, hvPlot plots all the columns except x (and except the columns used by by, groupby, row and col). Setting y explicitly is clearer and avoids subsetting the DataFrame first.

Split long data into subplots#

When your data is long, with a column that labels the groups like species below, combine subplots=True with by to draw one plot per value of that column.

penguins.hvplot.scatter(
    x='bill_length_mm', y='bill_depth_mm', by='species',
    subplots=True, width=250, height=200,
)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website.