Subplots#

Subplots#

When plotting multiple columns, hvPlot will overlay the plots onto one axis by default so that they can be compared easily in a compact format:

import xarray as xr
import hvplot.pandas  # noqa
import hvplot.xarray  # noqa

from hvplot.sample_data import airline_flights, us_crime

us_crime.hvplot(x='Year', y=['Burglary rate', 'Violent Crime rate', 'Robbery rate'], value_label='Rate')

If you wish, you can instead set subplots=True to split each column into its own separate plot:

us_crime.hvplot(x='Year', y=['Burglary rate', 'Violent Crime rate', 'Robbery rate'],
                value_label='Rate', subplots=True, width=300, height=200)

By default, the subplots will have linked, normalized axes, to facilitate comparing the numerical values across plots (try panning or zooming in any one of the plots, to see how the others change.)

However, if the data covers widely different numerical ranges, you can specify shared_axes=False to give each plot its own range:

us_crime.hvplot(x='Year', y=['Robbery',  'Robbery rate', 'Burglary', 'Burglary rate'], 
                width=350, height=300, subplots=True, shared_axes=False).cols(2)

(Notice the very different y axis ranges between the plots.) Here we also specified .cols(2) to allow up to two plots per line, wrapping the rest onto subsequent rows.

You can use the subplots=True (and shared_axes if desired) arguments when using the by keyword as well, if you want to group the data along a dimension:

flights = airline_flights.read()

flight_subset = flights[flights.carrier.isin(['OH', 'F9', 'US'])].sample(2000)

flight_subset.hvplot.scatter(x='arrdelay', y='depdelay', by='carrier',
                             subplots=True, width=250, height=250, alpha=0.1)

Grids#

subplot=True lays out plots sequentially, breaking lines if requested with the .cols() method but otherwise formatting each plot independently. You can instead arrange multidimensional data into an explicit 1D row of plots or a 2D grid of plots with shared axes, to allow easier comparisons across large numbers of plots. To make a row or grid plot, just specify the col keyword and add a row keyword if you want a grid:

flight_subset.sort_values('dayofweek').hvplot.scatter(x='arrdelay', y='depdelay', 
    row='dayofweek', col='carrier', alpha=0.2)

(Just declaring row to get a single column is not currently supported.) Here you can see that compared to the subplot versions above, the axis ticks and labels are shared to save space and make comparisons easier.

If you do not require an x axis and y axis for each plot at all, you can disable it with the xaxis and yaxis options:

air_ds = xr.tutorial.open_dataset('air_temperature').load()

air_ds.air.isel(time=slice(0, 5)).hvplot(col='time', xaxis=False, yaxis=False, colorbar=False)

Using subplots and grids in this way is supported throughout the hvPlot API, making it simple to determine how you want your data laid out and overlaid.

This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Right click to download this notebook from GitHub.