Small multiples aka facetted plots

I was hoping to be able to create small multiples using the keyword “by” (as described for scatter plots in python - Create a grid of plots with holoviews/hvplot and set the max number of columns - Stack Overflow)

nz.hvplot(by='Island', subplots=True)

Unfortunately, this fails with

File d:\mambaforge\envs\geocompy\lib\site-packages\holoviews\core\dimension.py:989, in Dimensioned.get_dimension(self, dimension, default, strict)
    987 name_map.update({util.dimension_sanitizer(dim.name): dim for dim in all_dims})
    988 if strict and dimension not in name_map:
--> 989     raise KeyError("Dimension %r not found." % dimension)
    990 else:
    991     return name_map.get(dimension, default)

KeyError: "Dimension 'Longitude' not found."

One workaround I’ve found is to create a Layout from a list of plots created like this instead:

Layout([group.hvplot(title=name) for name, group in nz.groupby('Island')])

But this feels much less intuitive.

Is there something I’m doing wrong when using “by”?


Full code:

I’m pretty sure it is a bug. An MRE is the following:

import geopandas as gpd
import hvplot.pandas

countries = gpd.read_file(gpd.datasets.get_path('naturalearth_lowres'))
countries.hvplot(geo=True, by="continent", subplots=True)

I have got the MRE to work with by but not subplots (yet). Will make a PR when I figure it out.

edit: Got it to work with subplots too. Will make a PR in the coming week.

edit 2: The PRs are holoviews #5325 and hvplot #761.

5 Likes

That was fast!!! :tada:

2 Likes

Thanks so much for the quick action. This will be very useful.

2 Likes