0

I have a scatter plot and want to add a vertical line to it as a marker.

However the scatter plot has x-range 0 to 2, but my vertical line is at x-range 6, so it's falling outside of the x-range of my scatter plot and not shown automatically.

What can I do to make my vertical line shown regardless of the x-ranges of my plot?


Sample code:

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

# my vline is not shown automatically because it's
# outside the range of my hv.Curve()
hv.Curve([[0,3], [1,4], [2,5]]) * hv.VLine(6)


Example plot (which doesnt show Vline):

line plot without extra vertical line

Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96

1 Answers1

0

1) You can of course change the xlim manually with:
hv.VLine(4).opts(xlim=(0, 7))

2) use .opts(apply_ranges=True) without having to look what the range on the x-axis should be:

curve = hv.Curve([[0,3], [1,4], [2,5]])

# use apply_ranges=True
vline = hv.VLine(4).opts(apply_ranges=True, line_width=10)

curve * vline

The same thing works also for hv.VSpan() and hv.HLine().

3) Use spikes hv.Spikes instead of vertical lines:
The advantage of Spikes is that it will also adjust the x-range for you automatically.

curve = hv.Curve([[0,3], [1,4], [2,5]])

# use apply_ranges=True
spikes = hv.Spikes([4]).opts(
    spike_length=3.0, 
    line_width=5,
    line_dash='dashed',
)

curve * spikes



Resulting plot:

use .opts(apply_ranges=True) to change your xrange automatically



Sander van den Oord
  • 10,986
  • 5
  • 51
  • 96