Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bokeh statistics operations, elements and plots #1985

Merged
merged 40 commits into from
Oct 31, 2017
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
fd2d570
Added initial structure for stats elements, operations and plots
philippjfr Oct 9, 2017
db0152b
Added support for virtual_vdims
philippjfr Oct 30, 2017
b479c34
Added StatisticalElement baseclass for Distribution and Bivariate
philippjfr Oct 30, 2017
381dae8
Improved bokeh statistical plot implementations
philippjfr Oct 30, 2017
c4f99f7
Allowed defining which backend to set options on
philippjfr Oct 30, 2017
dcf49bf
Improved kernel density operations
philippjfr Oct 30, 2017
6b544cc
Enabled virtual_vdims on StatisticalElements
philippjfr Oct 30, 2017
a5b0041
Made input_ranges optional on Operation
philippjfr Oct 30, 2017
a116df2
Recursively apply Compositor until no more matches found
philippjfr Oct 30, 2017
c65af98
Added Store method to transfer options from one Element to another
philippjfr Oct 30, 2017
c10af53
Added compositing operations for Distribution and Bivariate
philippjfr Oct 30, 2017
64ed9cc
Moved compositing operations into plotting utilities
philippjfr Oct 30, 2017
7425c2f
Removed stats element plots
philippjfr Oct 30, 2017
3162c28
Removed _virtual_vdims
philippjfr Oct 30, 2017
cb0ddb1
Apply compositor in renderer
philippjfr Oct 30, 2017
88ae142
Compositor improvements
philippjfr Oct 31, 2017
39a35f3
Fixes for univariate_kde operation
philippjfr Oct 31, 2017
84b2145
Readded statistics plot stubs
philippjfr Oct 31, 2017
b9546ac
Fix for Compositor tests
philippjfr Oct 31, 2017
1317c72
Allow Empty in AdjointLayout
philippjfr Oct 31, 2017
2ba2781
Improved Dimension handling for StatisticalElement
philippjfr Oct 31, 2017
f153c67
Small stylistic fixes for Distribution
philippjfr Oct 31, 2017
97a3437
Small fix for pandas statistical element handling
philippjfr Oct 31, 2017
105c64c
Removed Regression from comparisons
philippjfr Oct 31, 2017
e8667de
Improved statistics compositor definitions
philippjfr Oct 31, 2017
af6e84a
Guard against infinite Compositor recursion
philippjfr Oct 31, 2017
dd2b84e
Added transfer_options support to Compositor
philippjfr Oct 31, 2017
59644e6
Only apply Compositors if necessary
philippjfr Oct 31, 2017
6ce24a8
Various small fixes
philippjfr Oct 31, 2017
384f573
Fixed gridmatrix to work with statistics Elements
philippjfr Oct 31, 2017
7be66e0
Cleaned up KDE operations
philippjfr Oct 31, 2017
45f06c6
Added reference notebooks for statistics elements
philippjfr Oct 31, 2017
07b4fda
Added density grid demo notebooks
philippjfr Oct 31, 2017
5c5a9d0
Added filled options to DistributionPlots
philippjfr Oct 31, 2017
0b53c06
Added a unit test for style transfer
philippjfr Oct 31, 2017
37de415
Added tests for statistics elements
philippjfr Oct 31, 2017
6ad60d9
Fix for Compositor unit tests
philippjfr Oct 31, 2017
33d3b02
Removed left over Regression element test
philippjfr Oct 31, 2017
782f11a
Made suggested improvements to Compositor
philippjfr Oct 31, 2017
e3efb3a
Removed underscore from StatisticsElement baseclass
philippjfr Oct 31, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 81 additions & 0 deletions examples/gallery/demos/bokeh/iris_density_grid.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Most examples work across multiple plotting backends, this example is also available for:\n",
"\n",
"* [Matplotlib - iris_density_grid](../matplotlib/iris_splot_example.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"hv.extension('bokeh', width=95)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Declaring data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from bokeh.sampledata.iris import flowers\n",
"from holoviews.operation import gridmatrix\n",
"\n",
"iris_ds = hv.Dataset(flowers)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%opts Bivariate [bandwidth=0.5] (cmap='Blues')\n",
"hv.operation.gridmatrix(iris_ds, diagonal_type=hv.Distribution, chart_type=hv.Bivariate)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
81 changes: 81 additions & 0 deletions examples/gallery/demos/matplotlib/iris_density_grid.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Most examples work across multiple plotting backends, this example is also available for:\n",
"\n",
"* [Bokeh - iris_density_grid](../bokeh/iris_splot_example.ipynb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"hv.extension('matplotlib', width=95)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Declaring data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from bokeh.sampledata.iris import flowers\n",
"from holoviews.operation import gridmatrix\n",
"\n",
"iris_ds = hv.Dataset(flowers)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%opts Bivariate [bandwidth=0.5] (cmap='Blues')\n",
"hv.operation.gridmatrix(iris_ds, diagonal_type=hv.Distribution, chart_type=hv.Bivariate)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
124 changes: 124 additions & 0 deletions examples/reference/elements/bokeh/Bivariate.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<div class=\"contentcontainer med left\" style=\"margin-left: -50px;\">\n",
"<dl class=\"dl-horizontal\">\n",
" <dt>Title</dt> <dd> Bivariate Element</dd>\n",
" <dt>Dependencies</dt> <dd>Bokeh, Matplotlib, SciPy</dd>\n",
" <dt>Backends</dt> <dd><a href='./Bivariate.ipynb'>Bokeh</a></dd> <dd><a href='../matplotlib/Bivariate.ipynb'>Matplotlib</a></dd>\n",
"</dl>\n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"hv.extension('bokeh')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"``Bivariate`` provides a convenient way to visualize a 2D distribution of values as a [Kernel density estimate](https://en.wikipedia.org/wiki/Kernel_density_estimation) and therefore provides a 2D extension to the ``Distribution`` element. Kernel density estimation is a non-parametric way to estimate the probability density function of a random variable.\n",
"\n",
"The KDE works by placing a Gaussian kernel at each sample with the supplied bandwidth, which are then summed to produce the density estimate. By default the bandwidth is determined using the Scott's method, which usually produces good results, but it may be overridden by an explicit value.\n",
"\n",
"To start with we will create a ``Bivariate`` with 1,000 normally distributed samples:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"normal = np.random.randn(1000, 2)\n",
"hv.Bivariate(normal)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A ``Bivariate`` might be filled or not and we can define a ``cmap`` to control the coloring:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%opts Bivariate [filled=True colorbar=True width=350 toolbar='above'] (cmap='Blues')\n",
"hv.Bivariate(normal)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can set explicit values for the ``bandwidth`` to see the effect. Since the densities will vary across the ``NdLayout`` we will enable axiswise normalization ensuring they are normalized separately:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%opts Bivariate {+axiswise}\n",
"hv.NdLayout({bw: hv.Bivariate(normal).opts(plot=dict(bandwidth=bw))\n",
" for bw in [0.05, 0.1, 0.5, 1]}, 'Bandwidth').cols(2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Underlying the ``Bivariate`` element is the ``bivariate_kde`` operation, which computes the KDE for us automatically when we plot the element. We can also use this operation directly and print the output highlighting the fact that the operation simply returns an ``Contours`` or ``Polygons`` element. It also affords more control over the parameters letting us directly set not only the ``bandwidth`` and ``cut`` values but also a ``x_range``, ``y_range``, ``bw_method`` and the number of samples (``n_samples``) to approximate the KDE with:\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from holoviews.operation.stats import bivariate_kde\n",
"dist = hv.Bivariate(normal)\n",
"kde = bivariate_kde(dist, x_range=(-4, 4), y_range=(-4, 4), bw_method='silverman', n_samples=20)\n",
"kde"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading