Skip to content

Commit

Permalink
Merge 7108ad7 into a49d691
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Apr 28, 2017
2 parents a49d691 + 7108ad7 commit e23a8b9
Show file tree
Hide file tree
Showing 7 changed files with 557 additions and 0 deletions.
88 changes: 88 additions & 0 deletions examples/streams/bokeh/Bounds_Selection.ipynb
@@ -0,0 +1,88 @@
{
"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> Bounds & selection stream example</dd>\n",
" <dt>Description</dt> <dd>A linked streams example demonstrating how to use Bounds and Selection streams together.</dd>\n",
" <dt>Backends</dt> <dd> Bokeh</dd>\n",
" <dt>Tags</dt> <dd> streams, linked, position, interactive</dd>\n",
" </dl>\n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"from holoviews import streams\n",
"hv.notebook_extension('bokeh')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%opts Histogram {+framewise}\n",
"\n",
"# Declare distribution of Points\n",
"points = hv.Points(np.random.multivariate_normal((0, 0), [[1, 0.1], [0.1, 1]], (1000,)))\n",
"\n",
"# Declare points selection selection\n",
"sel = streams.Selection1D(source=points)\n",
"\n",
"# Declare DynamicMap computing mean y-value of selection\n",
"mean_sel = hv.DynamicMap(lambda index: hv.HLine(points['y'][index].mean() if index else -10),\n",
" kdims=[], streams=[sel])\n",
"\n",
"# Declare a Bounds stream and DynamicMap to get box_select geometry and draw it\n",
"box = streams.Bounds(source=points, bounds=(0,0,0,0))\n",
"bounds = hv.DynamicMap(lambda bounds: hv.Bounds(bounds), streams=[box])\n",
"\n",
"# Declare DynamicMap to apply bounds selection\n",
"dmap = hv.DynamicMap(lambda bounds: points.select(x=(bounds[0], bounds[2]),\n",
" y=(bounds[1], bounds[3])),\n",
" streams=[box])\n",
"\n",
"# Compute histograms of selection along x-axis and y-axis\n",
"yhist = hv.operation.histogram(dmap, bin_range=points.range('y'), dimension='y', dynamic=True, normed=False)\n",
"xhist = hv.operation.histogram(dmap, bin_range=points.range('x'), dimension='x', dynamic=True, normed=False)\n",
"\n",
"# Combine components and display\n",
"points * mean_sel * bounds << yhist << xhist"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<center><img src=\"http://assets.holoviews.org/gifs/bounds_selection.gif\" width=400></center>"
]
}
],
"metadata": {
"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
}
77 changes: 77 additions & 0 deletions examples/streams/bokeh/HeatMap_Tap.ipynb
@@ -0,0 +1,77 @@
{
"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> HeatMap Tap stream example</dd>\n",
" <dt>Description</dt> <dd>A linked streams example demonstrating how use Tap stream on a HeatMap to display more detail.</dd>\n",
" <dt>Backends</dt> <dd> Bokeh</dd>\n",
" <dt>Tags</dt> <dd> streams, tap, interactive</dd>\n",
" </dl>\n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"from holoviews import streams\n",
"hv.notebook_extension('bokeh')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%opts HeatMap [width=400 height=400 tools=['hover'] xrotation=90] Histogram [width=400 height=400] {+framewise}\n",
"\n",
"# Declare dataset\n",
"dataset = hv.Dataset(df, vdims=['Temperature'])\n",
"\n",
"# Declare HeatMap\n",
"heatmap = hv.HeatMap(dataset.aggregate(['Year', 'Country'], np.mean))\n",
"\n",
"# Declare Tap stream with heatmap as source and initial values\n",
"posxy = hv.streams.Tap(source=heatmap, x=1951, y='A')\n",
"\n",
"# Define function to compute histogram based on tap location\n",
"def tap_histogram(x, y):\n",
" return hv.operation.histogram(dataset.select(Country=y, Year=int(x)), normed=False).relabel(group='Tap Selection')\n",
"\n",
"heatmap + hv.DynamicMap(tap_histogram, kdims=[], streams=[posxy])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<center><img src=\"http://assets.holoviews.org/gifs/heatmap_tap.gif\" width=600></center>"
]
}
],
"metadata": {
"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
}
78 changes: 78 additions & 0 deletions examples/streams/bokeh/Linked_Pointer_Crosssection.ipynb
@@ -0,0 +1,78 @@
{
"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> Linked pointer cross-section example</dd>\n",
" <dt>Description</dt> <dd>A linked streams example demonstrating how to use PointerXY stream linked across two plots.</dd>\n",
" <dt>Backends</dt> <dd> Bokeh</dd>\n",
" <dt>Tags</dt> <dd> streams, linked, position, interactive</dd>\n",
" </dl>\n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"from holoviews import streams\n",
"hv.notebook_extension('bokeh')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%opts Curve [width=100]\n",
"\n",
"# Create two images\n",
"x,y = np.meshgrid(np.linspace(-5,5,101), np.linspace(5,-5,101))\n",
"img1 = hv.Image(np.sin(x**2+y**2))\n",
"img2 = hv.Image(np.sin(x**2+y**3))\n",
"\n",
"# Declare PointerX and dynamic VLine\n",
"posx = hv.streams.PointerX()\n",
"vline = hv.DynamicMap(lambda x: hv.VLine(x or -100), streams=[posx])\n",
"\n",
"# Declare cross-sections at PointerX location\n",
"crosssection1 = hv.DynamicMap(lambda x: img1.sample(x=x if x else 0), streams=[posx])\n",
"crosssection2 = hv.DynamicMap(lambda x: img2.sample(x=x if x else 0), streams=[posx])\n",
"\n",
"# Combine images, vline and cross-sections\n",
"((img1 * vline) << crosssection1) + ((img2 * vline) << crosssection2)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<center><img src=\"http://assets.holoviews.org/gifs/linked_pointer_crosssection.gif\" width=600></center>"
]
}
],
"metadata": {
"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
}
81 changes: 81 additions & 0 deletions examples/streams/bokeh/Multiple_Selection.ipynb
@@ -0,0 +1,81 @@
{
"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> Multiple selection streams example</dd>\n",
" <dt>Description</dt> <dd>A linked streams example demonstrating how to use multiple Selection1D streams on separate Points objects.</dd>\n",
" <dt>Backends</dt> <dd> Bokeh</dd>\n",
" <dt>Tags</dt> <dd> streams, linked, selection, interactive</dd>\n",
" </dl>\n",
"</div>"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"from holoviews import streams\n",
"hv.notebook_extension('bokeh')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"%%opts Points [tools=['box_select', 'lasso_select', 'tap']]\n",
"\n",
"# Declare two sets of points generated from multivariate distribution\n",
"points = hv.Points(np.random.multivariate_normal((0, 0), [[1, 0.1], [0.1, 1]], (1000,)))\n",
"points2 = hv.Points(np.random.multivariate_normal((3, 3), [[1, 0.1], [0.1, 1]], (1000,)))\n",
"\n",
"# Declare two selection streams and set points and points2 as the source of each\n",
"sel1 = streams.Selection1D(source=points)\n",
"sel2 = streams.Selection1D(source=points2)\n",
"\n",
"# Declare DynamicMaps to show mean y-value of selection as HLine\n",
"hline1 = hv.DynamicMap(lambda index: hv.HLine(points['y'][index].mean() if index else -10), streams=[sel1])\n",
"hline2 = hv.DynamicMap(lambda index: hv.HLine(points2['y'][index].mean() if index else -10), streams=[sel2])\n",
"\n",
"# Combine points and dynamic HLines\n",
"points * points2 * hline1 * hline2"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<center><img src=\"http://assets.holoviews.org/gifs/multiple_selection.gif\" width=350></center>"
]
}
],
"metadata": {
"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 e23a8b9

Please sign in to comment.