I’d like to replace a square legend handle with a hexagon, so that the handle corresponds with the plotted data. I’ve tried a number of methods, none of which work. Here is one:
import geoviews as gv
from geoviews import opts
from bokeh.models import HexTile, ColumnDataSource, GlyphRenderer
import geoviews.tile_sources as gts
from bokeh.io import show
gv.extension("bokeh")
leg_source = ColumnDataSource({"q": [0], "r": [0]})
leg_glyph = HexTile(q="q", r="r")
renderer = GlyphRenderer(data_source=leg_source, glyph=leg_glyph)
# df is a GeoDataFrame with a "weight" column
polys = gv.Polygons(df, vdims=["weight"], crs=ccrs.PlateCarree(), group="polys", label="LOI similarity")
poly_opts = opts.Polygons(cmap="Viridis", alpha=0.8, width=700, height=700, line_color="none", cnorm="log", clim=(0.01, np.nan), show_legend=True, muted_fill_alpha=0)
layout = (gts.OSM * polys).opts(poly_opts)
plot = gv.render(layout)
plot.legend[0].items[0].renderers[0] = renderer
show(plot)
this shows an error:
ERROR:bokeh.core.validation.check:E-1001 (BAD_COLUMN_NAME): Glyph refers to nonexistent column name. This could either be due to a misspelling or typo, or due to an expected column being missing. : key "line_color" value "none" [renderer: GlyphRenderer(id='2350', ...)]
and the handle doesn’t appear in the legend but the data are displayed.
I’ve tried hooks and manually creating a bokeh Legend
and adding it to layout
as well. Any ideas?