Skip to content

Commit

Permalink
Updated eleven more notebooks in the bokeh gallery
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens committed Nov 26, 2018
1 parent 19bfaac commit 200fbde
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 48 deletions.
27 changes: 18 additions & 9 deletions examples/gallery/demos/bokeh/legend_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"from holoviews import opts\n",
"hv.extension('bokeh')"
]
},
Expand All @@ -39,8 +40,13 @@
"y = np.sin(x)\n",
"\n",
"scatter1 = hv.Scatter((x, y), label='sin(x)')\n",
"scatter2 = hv.Scatter((x, y*2), label='2*sin(x)')\n",
"scatter3 = hv.Scatter((x, y*3), label='3*sin(x)')"
"scatter2 = hv.Scatter((x, y*2), label='2*sin(x)').relabel(group='Scatter2')\n",
"scatter3 = hv.Scatter((x, y*3), label='3*sin(x)').relabel(group='Scatter3')\n",
"scatter4 = hv.Scatter(scatter3).relabel(group='Scatter4')\n",
"\n",
"curve1 = hv.Curve(scatter1)\n",
"curve2 = hv.Curve(scatter2).relabel(group='Curve2')\n",
"curve3 = hv.Curve(scatter3).relabel(group='Curve3')"
]
},
{
Expand All @@ -56,14 +62,17 @@
"metadata": {},
"outputs": [],
"source": [
"example1 = scatter1 * scatter2.options(color='orange') * scatter3.options(color='green')\n",
"example2 = (\n",
" scatter1 * hv.Curve(scatter1) *\n",
" hv.Curve(scatter2).options(line_dash=(4, 4), color='orange') *\n",
" scatter3.options(line_color='green', marker='square', fill_alpha=0, size=5) * hv.Curve(scatter3)\n",
")\n",
"example1 = scatter1 * scatter2 * scatter3\n",
"example2 = scatter1 * curve1 * curve2 * scatter4 * curve3\n",
"\n",
"layout = example1.relabel(\"Legend Example\") + example2.relabel(\"Another Legend Example\")\n",
"\n",
"example1.relabel(\"Legend Example\") + example2.relabel(\"Another Legend Example\")"
"layout.options(\n",
" opts.Scatter('Scatter2', color='orange'),\n",
" opts.Scatter('Scatter3', color='green'),\n",
" opts.Scatter('Scatter4', line_color='green', marker='square', fill_alpha=0, size=5),\n",
" opts.Curve('Curve2', line_dash=(4, 4), color='orange'),\n",
" opts.Curve('Curve3', color='orange'))"
]
}
],
Expand Down
6 changes: 4 additions & 2 deletions examples/gallery/demos/bokeh/route_chord.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"outputs": [],
"source": [
"import holoviews as hv\n",
"from holoviews import opts, dim\n",
"from bokeh.sampledata.airport_routes import routes, airports\n",
"\n",
"hv.extension('bokeh')"
Expand Down Expand Up @@ -57,8 +58,9 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Chord [labels='City' width=800 height=800] (edge_color=dim('SourceID').str() node_color=dim('AirportID').str() cmap='Category20')\n",
"busiest_airports"
"busiest_airports.options(\n",
" opts.Chord(cmap='Category20', edge_color=dim('SourceID').str(), \n",
" height=800, labels='City', node_color=dim('AirportID').str(), width=800))"
]
}
],
Expand Down
11 changes: 7 additions & 4 deletions examples/gallery/demos/bokeh/scatter_economic.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"source": [
"import pandas as pd\n",
"import holoviews as hv\n",
"from holoviews import opts\n",
"hv.extension('bokeh')"
]
},
Expand Down Expand Up @@ -53,11 +54,13 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Scatter [width=700 height=400 scaling_method='width' scaling_factor=2 size_index=2 show_grid=True] \n",
"%%opts Scatter (color=Cycle('Category20') line_color='k')\n",
"%%opts NdOverlay [legend_position='left' show_frame=False]\n",
"gdp_unem_scatter = macro.to.scatter('Year', ['GDP Growth', 'Unemployment'])\n",
"gdp_unem_scatter.overlay('Country')"
"overlay = gdp_unem_scatter.overlay('Country')\n",
"overlay.options(\n",
" opts.Scatter(width=700, height=400, scaling_method='width', scaling_factor=2, \n",
" size_index=2, show_grid=True, color=hv.Cycle('Category20'), line_color='k'),\n",
" opts.NdOverlay(legend_position='left', show_frame=False)\n",
")"
]
}
],
Expand Down
5 changes: 3 additions & 2 deletions examples/gallery/demos/bokeh/square_limit.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"outputs": [],
"source": [
"import holoviews as hv\n",
"from holoviews import opts\n",
"import numpy as np\n",
"from matplotlib.path import Path\n",
"from matplotlib.transforms import Affine2D\n",
Expand Down Expand Up @@ -125,12 +126,12 @@
"metadata": {},
"outputs": [],
"source": [
"%%opts Spline [width=600 height=600 xaxis=None yaxis=None]\n",
"fish = hv.Spline((spline, [1,4,4,4]*34)) # Cubic splines\n",
"smallfish = flip(rot45(fish))\n",
"t = fish * smallfish * rot(rot(rot(smallfish)))\n",
"u = smallfish * rot(smallfish) * rot(rot(smallfish)) * rot(rot(rot(smallfish)))\n",
"squarelimit(3,u,t)"
"squarelimit(3,u,t).options(\n",
" opts.Spline(width=600, height=600, xaxis=None, yaxis=None))"
]
}
],
Expand Down
9 changes: 5 additions & 4 deletions examples/gallery/demos/bokeh/step_chart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"outputs": [],
"source": [
"import holoviews as hv\n",
"from holoviews import opts\n",
"hv.extension('bokeh')"
]
},
Expand Down Expand Up @@ -59,10 +60,10 @@
"metadata": {},
"outputs": [],
"source": [
"options = {'Curve': dict(interpolation='steps-mid', width=400, height=400, \n",
" line_dash=hv.Cycle(values=['dashed', 'solid'])),\n",
" 'Overlay': dict(legend_position='top_left')}\n",
"postage.options(options)"
"postage.options(\n",
" opts.Curve(interpolation='steps-mid', width=400, height=400, \n",
" line_dash=hv.Cycle(values=['dashed', 'solid'])),\n",
" opts.Overlay(legend_position='top_left'))"
]
}
],
Expand Down
12 changes: 7 additions & 5 deletions examples/gallery/demos/bokeh/stocks_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"import numpy as np\n",
"import pandas as pd\n",
"import holoviews as hv\n",
"from holoviews import opts\n",
"hv.extension('bokeh')"
]
},
Expand All @@ -44,7 +45,7 @@
"def get_curve(data, label=''):\n",
" df = pd.DataFrame(data)\n",
" df['date'] = df.date.astype('datetime64[ns]')\n",
" return hv.Curve(df, ('date', 'Date'), ('adj_close', 'Price'), label=label).options(color=color_cycle)\n",
" return hv.Curve(df, ('date', 'Date'), ('adj_close', 'Price'), label=label)\n",
"\n",
"hv.Dimension.type_formatters[np.datetime64] = '%Y'\n",
"\n",
Expand All @@ -71,10 +72,11 @@
"metadata": {},
"outputs": [],
"source": [
"plot_opts = dict(width=400, height=400, legend_position='top_left')\n",
"stocks = (aapl * goog * ibm * msft).options(**dict(plot_opts))\n",
"appl_stats = avg_scatter.options(alpha=0.2, size=4, color='darkgrey') * avg_curve.options(color='navy')\n",
"stocks + appl_stats.options(**plot_opts)"
"((aapl * goog * ibm * msft) + (avg_scatter * avg_curve)).options(\n",
" opts.Curve(color=color_cycle),\n",
" opts.Curve('Curve.Average', color='navy'),\n",
" opts.Scatter(alpha=0.2, size=4, color='darkgrey'),\n",
" opts.Overlay(width=400, height=400, legend_position='top_left'))"
]
}
],
Expand Down
6 changes: 4 additions & 2 deletions examples/gallery/demos/bokeh/texas_choropleth_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"outputs": [],
"source": [
"import holoviews as hv\n",
"from holoviews import opts\n",
"hv.extension('bokeh')"
]
},
Expand Down Expand Up @@ -57,9 +58,10 @@
"metadata": {},
"outputs": [],
"source": [
"choropleth.options(logz=True, tools=['hover'], xaxis=None, yaxis=None,\n",
"choropleth.options(\n",
" opts.Polygons(logz=True, tools=['hover'], xaxis=None, yaxis=None,\n",
" show_grid=False, show_frame=False, width=500, height=500,\n",
" color_index='Unemployment', colorbar=True, toolbar='above', line_color='white')"
" color_index='Unemployment', colorbar=True, toolbar='above', line_color='white'))"
]
}
],
Expand Down
11 changes: 8 additions & 3 deletions examples/gallery/demos/bokeh/timeseries_range_tool.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"import numpy as np\n",
"import pandas as pd\n",
"import holoviews as hv\n",
"from holoviews import opts\n",
"\n",
"from holoviews.plotting.links import RangeToolLink\n",
"\n",
Expand Down Expand Up @@ -63,12 +64,16 @@
"metadata": {},
"outputs": [],
"source": [
"tgt = aapl_curve.options(width=800, labelled=['y']).relabel('AAPL close price')\n",
"src = aapl_curve.options(width=800, height=100, yaxis=None)\n",
"tgt = aapl_curve.relabel('AAPL close price')\n",
"src = aapl_curve.relabel(group='View')\n",
"\n",
"RangeToolLink(src, tgt)\n",
"\n",
"(tgt + src).options(shared_axes=False, clone=False).cols(1)"
"layout = (tgt + src).cols(1)\n",
"layout.options(\n",
" opts.Curve(width=800, labelled=['y']),\n",
" opts.Curve('View', width=800, height=100, yaxis=None),\n",
" opts.Layout(shared_axes=False), clone=False)\n"
]
}
],
Expand Down
12 changes: 5 additions & 7 deletions examples/gallery/demos/bokeh/topographic_hillshading.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"outputs": [],
"source": [
"import holoviews as hv\n",
"from holoviews import opts\n",
"hv.extension('bokeh')"
]
},
Expand All @@ -35,7 +36,6 @@
"outputs": [],
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"import matplotlib.pyplot as plt\n",
"from matplotlib.cbook import get_sample_data\n",
"from matplotlib.colors import LightSource\n",
Expand All @@ -60,11 +60,7 @@
" for mode in ['hsv', 'overlay', 'soft']:\n",
" rgb = ls.shade(z, cmap=cmap, blend_mode=mode,\n",
" vert_exag=ve, dx=dx, dy=dy)\n",
" grid[mode, ve] = hv.RGB(rgb)\n",
" \n",
"opts = {'GridMatrix': {'plot': dict(xaxis='bottom', shared_xaxis=False, shared_yaxis=False,\n",
" yaxis='left', bgcolor='white')},\n",
" 'Image': {'style': dict(cmap='gray')}}"
" grid[mode, ve] = hv.RGB(rgb)"
]
},
{
Expand All @@ -80,7 +76,9 @@
"metadata": {},
"outputs": [],
"source": [
"grid(opts)"
"grid.options(\n",
" opts.GridMatrix(xaxis='bottom', yaxis='left', shared_xaxis=False, shared_yaxis=False),\n",
" opts.Image(cmap='gray'))"
]
}
],
Expand Down
12 changes: 6 additions & 6 deletions examples/gallery/demos/bokeh/us_unemployment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
"source": [
"import pandas as pd\n",
"import holoviews as hv\n",
"from holoviews import opts\n",
"from matplotlib.colors import ListedColormap\n",
"hv.extension('bokeh')"
]
},
Expand All @@ -37,10 +39,7 @@
"source": [
"from bokeh.sampledata.unemployment1948 import data\n",
"\n",
"colors = [\"#75968f\", \"#a5bab7\", \"#c9d9d3\", \"#e2e2e2\", \"#dfccce\", \"#ddb7b1\", \"#cc7878\", \"#933b41\", \"#550b1d\"]\n",
"\n",
"data = pd.melt(data.drop('Annual', 1), id_vars='Year', var_name='Month', value_name='Unemployment')\n",
"\n",
"heatmap = hv.HeatMap(data, label=\"US Unemployment (1948 - 2013)\")"
]
},
Expand All @@ -57,9 +56,10 @@
"metadata": {},
"outputs": [],
"source": [
"from matplotlib.colors import ListedColormap\n",
"heatmap.options(width=900, height=400, xrotation=45, xaxis='top', labelled=[], \n",
" tools=['hover'], cmap=ListedColormap(colors))"
"colors = [\"#75968f\", \"#a5bab7\", \"#c9d9d3\", \"#e2e2e2\", \"#dfccce\", \"#ddb7b1\", \"#cc7878\", \"#933b41\", \"#550b1d\"]\n",
"heatmap.options(\n",
" opts.HeatMap(width=900, height=400, xrotation=45, xaxis='top', labelled=[], \n",
" tools=['hover'], cmap=ListedColormap(colors)))"
]
}
],
Expand Down
14 changes: 10 additions & 4 deletions examples/gallery/demos/bokeh/verhulst_mandelbrot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"from itertools import islice\n",
"import numpy as np\n",
"import holoviews as hv\n",
"from holoviews import opts\n",
"hv.extension('bokeh')"
]
},
Expand Down Expand Up @@ -96,15 +97,20 @@
"metadata": {},
"outputs": [],
"source": [
"%%output size=120\n",
"%%opts Image (cmap='Reds') [logz=True xaxis=None yaxis=None] Points (size=0.5 color='g') \n",
"%%opts Curve (color='teal' line_width=1) HLine (color='k' line_dash='dashed')\n",
"bifurcation_diagram = hv.Points([(mapping(rate), pop) for rate in growth_rates for \n",
" (gen, pop) in enumerate(logistic_map(gens=110, growth=rate))\n",
" if gen>=100]) # Discard the first 100 generations to view attractors more easily\n",
"\n",
"vlines = hv.Overlay([hv.Curve([(mapping(pos),0), ((mapping(pos),1.4))]) for pos in bifurcations])\n",
"hv.Image(mandelbrot(800,800, 45, 46).copy(), bounds=(-2, -1.4, 0.8, 1.4)) * bifurcation_diagram * hv.HLine(0) * vlines"
"overlay = (hv.Image(mandelbrot(800,800, 45, 46).copy(), bounds=(-2, -1.4, 0.8, 1.4))\n",
" * bifurcation_diagram * hv.HLine(0) * vlines)\n",
"\n",
"hv.output(size=120)\n",
"overlay.options(\n",
" opts.HLine(color='k', line_dash='dashed'),\n",
" opts.Image(cmap='Reds', logz=True, xaxis=None, yaxis=None),\n",
" opts.Points(size=0.5, color='g'),\n",
" opts.Curve(color='teal', line_width=1))"
]
}
],
Expand Down

0 comments on commit 200fbde

Please sign in to comment.