holoviz / hvplot

A high-level plotting API for pandas, dask, xarray, and networkx built on HoloViews
https://hvplot.holoviz.org
BSD 3-Clause "New" or "Revised" License
1.09k stars 105 forks source link

Unexpected bokeh interactive legend behavior with Geodataframe.hvplot.polygons() #381

Open scottyhq opened 4 years ago

scottyhq commented 4 years ago

Is your feature request related to a problem? Please describe. the legend=True keyword for hvplot.polygons() creates an interactive bokeh legend only when coupled with geoviews tiles. I expect this legend to be interactive without composing with a geoviews object.

Describe the solution you'd like It would be excellent if hvplot.polygons() also worked with a row of polygons such that each column gets a selectable legend entry.

Describe alternatives you've considered I've noted a workaround in the gist linked below, but it's a bit ugly (creating a list of separate geodataframes with a single geometry each and using hv.NdOverlay). The relevant cell being:

# Workaround for now - see "interactive legends" http://holoviews.org/user_guide/Plotting_with_Bokeh.html
gdfs = continents.apply(lambda x: gpd.GeoDataFrame(x).T, axis=1)
overlays = hv.NdOverlay({gdfs[i].index[0]: gdfs[i].hvplot(geo=True) for i in range(len(gdfs))})

Additional context The following notebook illustrates the current legend behavior and workaround: https://nbviewer.jupyter.org/gist/scottyhq/4ca5f96592fcde4eafa7451cd37cb305

maximlt commented 1 year ago

I can reproduce.

jsignell commented 1 year ago

It seems like what you want is to use by:

continents.hvplot(geo=True, by="continent")

This is failing on main, but works on my branch for #1055