'How do I get a full-height vertical line with a legend label in holoviews + bokeh?

I want to plot a vertical line in holoviews with the bokeh backend which has a label that shows up in my legend. I need this line to be the full height of the plot, regardless of whether it is alone or overlaid with other elements. How can I achieve this?

Example

I'm adding in a curve plot in the example because otherwise even elements that can appear in a legend just use their label as a title.

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

x = np.linspace(0, 1)
curve = hv.Curve((x, np.sin(x)), label="sin(x)")
vline = hv.VLine(0.5, label="vline")
curve * vline

This gives the following plot:

enter image description here

which has no label for the vertical line. How do I get the label to show up?



Solution 1:[1]

Based on Nathans 2 workarounds, there is a 3rd very easy workaround using Curve

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

x = np.linspace(0, 1)
curve = hv.Curve((x, np.sin(x)), label="sin(x)")
height = (curve.data["y"].min(), curve.data["y"].max())
xpos = 0.5

spikes = hv.Curve(([xpos]*2, height), label="mid")
spikes * curve

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 n4321d