Slope

Download this notebook from GitHub (right-click to download).


Title: Slope Element

Dependencies: Matplotlib

Backends: Bokeh, Matplotlib

In [1]:
import numpy as np
import holoviews as hv

hv.extension('matplotlib')

The Slope element is a type of annotation that plots a line with arbitrary slope and y-intercept.

In [2]:
gradient = 2
y_intercept = 15

# create random data
xpts = np.arange(0, 20)
ypts = gradient * xpts + y_intercept + np.random.normal(0, 4, 20)

scatter = hv.Scatter((xpts, ypts))
slope = hv.Slope(gradient, y_intercept)

scatter * slope.opts(color='red', linewidth=6)
Out[2]:

The Slope maybe also be directly be calculated from a set of Scatter points using the Slope.from_scatter method, which will infer the gradient and y-intercept automatically:

In [3]:
normal = hv.Scatter(np.random.randn(20, 2))

normal * hv.Slope.from_scatter(normal)
Out[3]:

For full documentation and the available style and plot options, use hv.help(hv.Slope).


Download this notebook from GitHub (right-click to download).