{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "#### **Title**: Slope Element\n", "\n", "**Dependencies**: Bokeh\n", "\n", "**Backends**: [Matplotlib](../matplotlib/VLine.ipynb), [Bokeh](./VLine.ipynb)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import holoviews as hv\n", "\n", "hv.extension('bokeh')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ``Slope`` element is a type of annotation that plots a line with arbitrary slope and y-intercept.\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gradient = 2\n", "y_intercept = 15\n", "\n", "# create random data\n", "xpts = np.arange(0, 20)\n", "ypts = gradient * xpts + y_intercept + np.random.normal(0, 4, 20)\n", "\n", "scatter = hv.Scatter((xpts, ypts))\n", "slope = hv.Slope(gradient, y_intercept)\n", "\n", "scatter.opts(size=10) * slope.opts(color='red', line_width=6)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "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:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "normal = hv.Scatter(np.random.randn(20, 2))\n", "\n", "normal.opts(size=10) * hv.Slope.from_scatter(normal)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For full documentation and the available style and plot options, use ``hv.help(hv.Slope).``" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 4 }