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

Title: Slope Element#

Dependencies: Matplotlib

Backends: Bokeh, Matplotlib

import numpy as np
import holoviews as hv


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

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)

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:

normal = hv.Scatter(np.random.randn(20, 2))

normal * hv.Slope.from_scatter(normal)

For full documentation and the available style and plot options, use

This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

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