-
-
Notifications
You must be signed in to change notification settings - Fork 403
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
361f1a0
commit 10515f7
Showing
8 changed files
with
321 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ | ||
"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", | ||
"from holoviews import opts\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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"#### **Title**: Slope Element\n", | ||
"\n", | ||
"**Dependencies**: Matplotlib\n", | ||
"\n", | ||
"**Backends**: [Bokeh](../bokeh/VLine.ipynb), [Matplotlib](./VLine.ipynb)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"import holoviews as hv\n", | ||
"from holoviews import opts\n", | ||
"\n", | ||
"hv.extension('matplotlib')" | ||
] | ||
}, | ||
{ | ||
"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 * slope.opts(color='red', linewidth=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 * 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.