Skip to content

Commit

Permalink
Added QuadMesh element example
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed May 31, 2017
1 parent 7408af2 commit ec64bb3
Showing 1 changed file with 106 additions and 0 deletions.
106 changes: 106 additions & 0 deletions examples/elements/bokeh/QuadMesh.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
{
"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> QuadMesh Element</dd>\n",
" <dt>Dependencies</dt> <dd>Bokeh</dd>\n",
" <dt>Backends</dt> <dd>[Bokeh](./QuadMesh.ipynb)</dd> <dd>[Matplotlib](../matplotlib/QuadMesh.ipynb)</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.notebook_extension('bokeh', 'matplotlib')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The basic ``QuadMesh`` is a 2D grid of bins specified as x-/y-values specifying a regular sampling or edges, with arbitrary sampling and an associated 2D array containing the bin values. The coordinate system of a ``QuadMesh`` is defined by the bin edges, therefore any index falling into a binned region will return the appropriate value. Since a ``QuadMesh`` can define arbitrary bin widths it can define any arbitrary sampling, such as a log scale:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%opts QuadMesh [tools=['hover']]\n",
"n = 8\n",
"xs = np.logspace(1, 3, n)\n",
"ys = np.linspace(1, 10, n)\n",
"zs = np.arange((n-1)**2).reshape(n-1, n-1)\n",
"qmesh = hv.QuadMesh((xs, ys, zs))\n",
"\n",
"qmesh + qmesh(plot=dict(logx=True))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Unlike ``Image`` objects, slices must be inclusive of the bin edges, otherwise the slicing semantics work just the same as in an Image. We can provide slices along the x- and y-axis to get a slice of the lower corner. To keep the same color range above we set the z-dimension range:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"qmesh[20:400, :8].redim.range(z=qmesh.range('z'))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Since we can reveal the values with a hover tool a QuadMesh can be used as an overlay which reveals the value on hover simply by casting the Image to a QuadMesh. By setting the ``alpha`` to 0 and defining a hover alpha and color we can highlight the selected value on hover:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%opts QuadMesh [tools=['hover']] (alpha=0 hover_line_alpha=1 hover_line_color='black')\n",
"img = hv.Image(np.random.rand(10,10))\n",
"img * hv.QuadMesh(img)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python [conda env:science]",
"language": "python",
"name": "conda-env-science-py"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.11"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit ec64bb3

Please sign in to comment.