holoviz / holoviews

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

Add legend to plot with only 1 curve #4196

Open SandervandenOord opened 4 years ago

SandervandenOord commented 4 years ago

Currently it is not possible to add a legend to a plot with only 1 curve. It would be nice if you could do that.

At the moment there's only a workaround such as creating an overlay with the same curve:

curve1 = hv.Curve([3, 4, 5], name='just one line')
curve1 * curve1

Would be nice if adding a legend to a plot would be more intuitive. image

See also: https://stackoverflow.com/questions/55490184/legend-does-not-appear-in-holoviews-for-only-1-line https://discourse.holoviz.org/t/how-to-get-a-legend-for-just-one-line-curve/121

Version using: Holoviews 1.13

LinuxIsCool commented 3 years ago

I think that this functionality would be extremely useful when composing plots. I'm struggling to get a legend for an overlay that is a composition of many single curve plots.

jbednar commented 3 years ago

@LinuxIsCool , can you post the code you are trying to run? Normally a legend is generated when you overlay multiple separate curves.

szarma commented 1 year ago

It does in fact show legend when overlaying separate curves, but seems by "over-plotting" the legend entry. Easy to spot with transparency

curves = []
for j in range(10):
    X = np.random.rand(10)
    t = np.arange(len(X))+j*len(X)*1.2
    curves += [hv.Curve((t,X), label='a').opts(alpha = .5)]
hv.Overlay(curves).opts(width=900)

bokeh_plot-7

related: https://discourse.holoviz.org/t/minor-aesthetic-inconsistent-behavior-for-legend-entry-referring-to-multiple-curves/4557