Title: Slope Element#
import numpy as np import holoviews as hv hv.extension('matplotlib')
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)
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