holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.7k stars 402 forks source link

Legend not working for hv.Graph elements #3509

Open bstadlbauer opened 5 years ago

bstadlbauer commented 5 years ago

When creating a hv.Points plot the following would create a legend:

import numpy as np
import holoviews as hv
hv.extension('bokeh')

a = hv.Points(((1, 2), (2, 3)))
a = a.relabel(label='foo')
b = a.relabel(label='bar')
a * b

bokeh_plot 2

However, the same seems not to be true for hv.Graph elements:

N = 8
node_indices = np.arange(N)
source = np.zeros(N)
target = node_indices

padding = dict(x=(-1.2, 1.2), y=(-1.2, 1.2))

graph_a = hv.Graph(((source, target),)).redim.range(**padding)
graph_a = graph_a.relabel('foo')
graph_b = graph_a.relabel('bar')
graph_a * graph_b

bokeh_plot 1

Is this an issue or is there any other way to create an interactive bokeh legend?

philippjfr commented 5 years ago

Is this an issue or is there any other way to create an interactive bokeh legend?

It is an issue and thanks for filing it (I forgot the last time I ran into this). HoloViews mostly relies on the figure glyph methods to generate legends and it seems the graph method does not auto-generate a legend. The easiest thing to do will be to add the legend manually in GraphPlot.

bstadlbauer commented 5 years ago

Thank you! @philippjfr Is there any place where I can help? If I know where to implement it (e.g. an example of another element adding a legend) I am happy to make a PR

philippjfr commented 5 years ago

I don't think there's anything in HoloViews you could copy, I think you'd have to look into what bokeh does internally to create a legend and then copy that approach for Graphs, or possibly a better approach would be to add support for it directly at the bokeh level.