Skip to content

Commit

Permalink
Add opts in doc 2 (#1763)
Browse files Browse the repository at this point in the history
* Replace (...) with .opts()

* Complements #1759
* Execute `git grep -lE '\)\((style|plot|norm)=' -- examples | xargs  perl -pi -e 's/\)\((style|plot|norm)=/).opts($1=/g'`
* Spot check notebooks

* A few more cases thanks to @ea42gh

* Manually search `git grep ')(' -- examples | grep -vE '.{255}'
* Fix cases by hand
`
  • Loading branch information
jordansamuels authored and jlstevens committed Jul 27, 2017
1 parent dcf4a61 commit 350b323
Show file tree
Hide file tree
Showing 26 changed files with 47 additions and 47 deletions.
2 changes: 1 addition & 1 deletion examples/gallery/apps/bokeh/game_of_life.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,6 @@ def update(pattern, counter, x, y):
pattern_dim = hv.Dimension('Pattern', values=sorted(shapes.keys()))
dmap = hv.DynamicMap(update, kdims=[pattern_dim], streams=[counter, tap])

doc = renderer.server_doc(dmap.redim.range(z=(0, 1))(**opts))
doc = renderer.server_doc(dmap.redim.range(z=(0, 1)).opts(**opts))
dmap.periodic(0.05, None)
doc.title = 'Game of Life'
2 changes: 1 addition & 1 deletion examples/gallery/demos/bokeh/area_chart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"source": [
"style = dict(fill_alpha=0.5)\n",
"\n",
"overlay = (python * pypy * jython)(style={'Area': style})\n",
"overlay = (python * pypy * jython).opts(style={'Area': style})\n",
"overlay.relabel(\"Area Chart\") + hv.Area.stack(overlay).relabel(\"Stacked Area Chart\")"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"max_year = ds['year'].max()\n",
"def get_labels():\n",
" return hv.NdOverlay({deg: hv.Text(max_year, ds[max_year, deg]+y_offsets.get(deg, 0),\n",
" deg, halign='left', fontsize=10)(style=dict(color=col))\n",
" deg, halign='left', fontsize=10).opts(style=dict(color=col))\n",
" for deg, col in zip(df.Degree.unique(), color_sequence)})"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/bokeh/histogram_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
" 'plot': dict(height=350, width=350, bgcolor=\"#E8DDCB\")},\n",
" 'Curve': {'norm': no_norm}, 'Layout': {'plot': dict(shared_axes=False)}}\n",
"\n",
"(norm + lognorm + gamma + beta + weibull)(opts).cols(2)"
"(norm + lognorm + gamma + beta + weibull).opts(opts).cols(2)"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/bokeh/legend_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"example1 = scatter1 * scatter2(style=dict(color='orange')) * scatter3(style=dict(color='green'))\n",
"example2 = (\n",
" scatter1 * hv.Curve(scatter1) *\n",
" hv.Curve(scatter2)(style=dict(line_dash=(4, 4), color='orange')) *\n",
" hv.Curve(scatter2).opts(style=dict(line_dash=(4, 4), color='orange')) *\n",
" scatter3(style=dict(line_color='green', marker='square', fill_alpha=0, size=5)) * hv.Curve(scatter3)\n",
")\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/bokeh/measles_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"\n",
"opts = {'HeatMap': {'plot': hm_opts}, 'Overlay': {'plot': overlay_opts}, 'VLine': {'style': vline_opts}}\n",
"\n",
"(heatmap + agg * vline * marker)(opts).cols(1)"
"(heatmap + agg * vline * marker).opts(opts).cols(1)"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions examples/gallery/demos/bokeh/stocks_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@
"scatter_style = dict(alpha=0.2, size=4, color='darkgrey')\n",
"curve_style = dict(color='navy')\n",
"\n",
"((aapl * goog * ibm * msft)(plot=plot_opts) +\n",
"(avg_scatter(style=scatter_style) * avg_curve(style=curve_style))(plot=plot_opts))"
"((aapl * goog * ibm * msft).opts(plot=plot_opts) +\n",
"(avg_scatter(style=scatter_style) * avg_curve(style=curve_style)).opts(plot=plot_opts))"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/matplotlib/area_chart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"source": [
"style = dict(alpha=0.5)\n",
"\n",
"overlay = (python * pypy * jython)(style={'Area': style})\n",
"overlay = (python * pypy * jython).opts(style={'Area': style})\n",
"overlay.relabel(\"Area Chart\") + hv.Area.stack(overlay).relabel(\"Stacked Area Chart\")"
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
"max_year = ds['year'].max()\n",
"def get_labels():\n",
" return hv.NdOverlay({deg: hv.Text(max_year, ds[max_year, deg]+y_offsets.get(deg, 0),\n",
" deg, halign='left', fontsize=10)(style=dict(color=col))\n",
" deg, halign='left', fontsize=10).opts(style=dict(color=col))\n",
" for deg, col in zip(df.Degree.unique(), color_sequence)})"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/matplotlib/histogram_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@
" 'plot': dict(bgcolor=\"#E8DDCB\")},\n",
" 'Curve': {'norm': no_norm}, 'Layout': {'plot': dict(hspace=0.2)}}\n",
"\n",
"(norm + lognorm + gamma + beta + weibull)(opts).cols(2)"
"(norm + lognorm + gamma + beta + weibull).opts(opts).cols(2)"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/matplotlib/legend_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"example1 = scatter1 * scatter2(style=dict(color='orange')) * scatter3(style=dict(color='green'))\n",
"example2 = (\n",
" scatter1 * hv.Curve(scatter1) *\n",
" hv.Curve(scatter2)(style=dict(linestyle='--', color='orange')) *\n",
" hv.Curve(scatter2).opts(style=dict(linestyle='--', color='orange')) *\n",
" scatter3(style=dict(color='green', marker='s')) * hv.Curve(scatter3)\n",
")\n",
"\n",
Expand Down
2 changes: 1 addition & 1 deletion examples/gallery/demos/matplotlib/measles_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"opts = {'Layout': {'plot': layout_opts}, 'HeatMap': {'plot': hm_opts},\n",
" 'Overlay': {'plot': overlay_opts}, 'VLine': {'style': vline_opts}}\n",
"\n",
"(heatmap + agg * vline * marker)(opts).cols(1)"
"(heatmap + agg * vline * marker).opts(opts).cols(1)"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions examples/gallery/demos/matplotlib/stocks_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
"scatter_style = dict(alpha=0.2, size=4, color='darkgrey')\n",
"curve_style = dict(color='navy')\n",
"\n",
"(aapl * goog * ibm * msft)(plot=plot_opts) +\\\n",
"(avg_scatter(style=scatter_style) * avg_curve(style=curve_style))(plot=plot_opts)"
"(aapl * goog * ibm * msft).opts(plot=plot_opts) +\\\n",
"(avg_scatter(style=scatter_style) * avg_curve(style=curve_style)).opts(plot=plot_opts)"
]
}
],
Expand Down
2 changes: 1 addition & 1 deletion examples/reference/elements/bokeh/Curve.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"outputs": [],
"source": [
"%%opts Curve [width=600] NdOverlay [legend_position='right']\n",
"hv.NdOverlay({interp: hv.Curve(points[::8])(plot=dict(interpolation=interp))\n",
"hv.NdOverlay({interp: hv.Curve(points[::8]).opts(plot=dict(interpolation=interp))\n",
" for interp in ['linear', 'steps-mid', 'steps-pre', 'steps-post']})"
]
}
Expand Down
6 changes: 3 additions & 3 deletions examples/reference/elements/bokeh/Polygons.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
"def rectangle(x=0, y=0, width=1, height=1):\n",
" return np.array([(x,y), (x+width, y), (x+width, y+height), (x, y+height)])\n",
"\n",
"(hv.Polygons([rectangle(width=2), rectangle(x=6, width=2)])(style={'fill_color': '#a50d0d'})\n",
"* hv.Polygons([rectangle(x=2, height=2), rectangle(x=5, height=2)])(style={'fill_color': '#ffcc00'})\n",
"* hv.Polygons([rectangle(x=3, height=2, width=2)])(style={'fill_color': 'cyan'}))"
"(hv.Polygons([rectangle(width=2), rectangle(x=6, width=2)]).opts(style={'fill_color': '#a50d0d'})\n",
"* hv.Polygons([rectangle(x=2, height=2), rectangle(x=5, height=2)]).opts(style={'fill_color': '#ffcc00'})\n",
"* hv.Polygons([rectangle(x=3, height=2, width=2)]).opts(style={'fill_color': 'cyan'}))"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions examples/reference/elements/bokeh/Spikes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
"outputs": [],
"source": [
"%%opts Spikes [spike_length=0.1] NdOverlay [show_legend=False]\n",
"hv.NdOverlay({i: hv.Spikes(np.random.randint(0, 100, 10), kdims=['Time'])(plot=dict(position=0.1*i))\n",
" for i in range(10)})(plot=dict(yticks=[((i+1)*0.1-0.05, i) for i in range(10)]))"
"hv.NdOverlay({i: hv.Spikes(np.random.randint(0, 100, 10), kdims=['Time']).opts(plot=dict(position=0.1*i))\n",
" for i in range(10)}).opts(plot=dict(yticks=[((i+1)*0.1-0.05, i) for i in range(10)]))"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/reference/elements/matplotlib/Curve.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"outputs": [],
"source": [
"%%opts NdOverlay [legend_position='right']\n",
"hv.NdOverlay({interp: hv.Curve(points[::8])(plot=dict(interpolation=interp))\n",
"hv.NdOverlay({interp: hv.Curve(points[::8]).opts(plot=dict(interpolation=interp))\n",
" for interp in ['linear', 'steps-mid', 'steps-pre', 'steps-post']})"
]
}
Expand Down
6 changes: 3 additions & 3 deletions examples/reference/elements/matplotlib/Polygons.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@
"def rectangle(x=0, y=0, width=1, height=1):\n",
" return np.array([(x,y), (x+width, y), (x+width, y+height), (x, y+height)])\n",
"\n",
"(hv.Polygons([rectangle(width=2), rectangle(x=6, width=2)])(style={'facecolor': '#a50d0d'})\n",
"* hv.Polygons([rectangle(x=2, height=2), rectangle(x=5, height=2)])(style={'facecolor': '#ffcc00'})\n",
"* hv.Polygons([rectangle(x=3, height=2, width=2)])(style={'facecolor': 'cyan'}))"
"(hv.Polygons([rectangle(width=2), rectangle(x=6, width=2)]).opts(style={'facecolor': '#a50d0d'})\n",
"* hv.Polygons([rectangle(x=2, height=2), rectangle(x=5, height=2)]).opts(style={'facecolor': '#ffcc00'})\n",
"* hv.Polygons([rectangle(x=3, height=2, width=2)]).opts(style={'facecolor': 'cyan'}))"
]
}
],
Expand Down
4 changes: 2 additions & 2 deletions examples/reference/elements/matplotlib/Spikes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@
"outputs": [],
"source": [
"%%opts Spikes [spike_length=0.1] NdOverlay [show_legend=False]\n",
"hv.NdOverlay({i: hv.Spikes(np.random.randint(0, 100, 10), kdims=['Time'])(plot=dict(position=0.1*i))\n",
" for i in range(10)})(plot=dict(yticks=[((i+1)*0.1-0.05, i) for i in range(10)]))"
"hv.NdOverlay({i: hv.Spikes(np.random.randint(0, 100, 10), kdims=['Time']).opts(plot=dict(position=0.1*i))\n",
" for i in range(10)}).opts(plot=dict(yticks=[((i+1)*0.1-0.05, i) for i in range(10)]))"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion examples/reference/elements/plotly/Curve.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"metadata": {},
"outputs": [],
"source": [
"hv.NdOverlay({interp: hv.Curve(points[::8])(plot=dict(interpolation=interp))\n",
"hv.NdOverlay({interp: hv.Curve(points[::8]).opts(plot=dict(interpolation=interp))\n",
" for interp in ['linear', 'steps-mid', 'steps-pre', 'steps-post']})"
]
}
Expand Down
2 changes: 1 addition & 1 deletion examples/reference/streams/bokeh/Selection1D_points.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
" label = 'Mean x, y: %.3f, %.3f' % tuple(selected.array().mean(axis=0))\n",
" else:\n",
" label = 'No selection'\n",
" return selected.relabel(label)(style=dict(color='red'))\n",
" return selected.relabel(label).opts(style=dict(color='red'))\n",
"\n",
"# Combine points and DynamicMap\n",
"points + hv.DynamicMap(selected_info, streams=[selection])"
Expand Down
2 changes: 1 addition & 1 deletion examples/topics/simulation/sri_model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@
"%%opts HeatMap [show_values=False aspect=1.5 xrotation=90] Histogram {+axiswise} Layout [fig_size=150]\n",
"group_colors = zip(quantities, ['Blues', 'Reds', 'Greens', 'Purples'])\n",
"hv.Layout([hv.Table(df).to.heatmap(['pVaccinated', 'Connections'],\n",
" q, [], group=q)(style=dict(cmap=c)).hist()\n",
" q, [], group=q).opts(style=dict(cmap=c)).hist()\n",
" for q, c in group_colors]).cols(2)"
]
},
Expand Down
12 changes: 6 additions & 6 deletions examples/user_guide/09-Indexing_and_Selecting_Data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
"outputs": [],
"source": [
"img_coords = hv.Points(img.table(), extents=extents)\n",
"labeled_img = img * img_coords * hv.Points([img.closest([(5.1,4.9)])])(style=dict(color='r'))\n",
"labeled_img = img * img_coords * hv.Points([img.closest([(5.1,4.9)])]).opts(style=dict(color='r'))\n",
"img + labeled_img + img.sample([(5.1,4.9)])"
]
},
Expand Down Expand Up @@ -451,9 +451,9 @@
"source": [
"%%output backend='matplotlib' size=120\n",
"sample_style = dict(edgecolors='k', alpha=1)\n",
"all_samples = obs_hmap.table().to.scatter3d()(style=dict(alpha=0.15))\n",
"all_samples = obs_hmap.table().to.scatter3d().opts(style=dict(alpha=0.15))\n",
"sampled = obs_hmap.sample((3,3))\n",
"subsamples = sampled.to.scatter3d()(style=sample_style)\n",
"subsamples = sampled.to.scatter3d().opts(style=sample_style)\n",
"all_samples * subsamples + sampled"
]
},
Expand All @@ -472,7 +472,7 @@
"source": [
"%%output backend='matplotlib' size=120\n",
"sampled = obs_hmap.sample((3,3), bounds=(2,5,5,10))\n",
"subsamples = sampled.to.scatter3d()(style=sample_style)\n",
"subsamples = sampled.to.scatter3d().opts(style=sample_style)\n",
"all_samples * subsamples + sampled"
]
},
Expand Down Expand Up @@ -500,7 +500,7 @@
" key_dimensions=['Observation'])\n",
"all_samples = curve.table().to.points()\n",
"sampled = curve.sample([0, 2, 4, 6, 8])\n",
"sampling = all_samples * sampled.to.points(extents=extents)(style=dict(color='r'))\n",
"sampling = all_samples * sampled.to.points(extents=extents).opts(style=dict(color='r'))\n",
"sampling + sampled"
]
},
Expand All @@ -518,7 +518,7 @@
"outputs": [],
"source": [
"sampled = curve.table().select(Observation=(0, 1.1), x={0, 2, 4, 6, 8})\n",
"sampling = all_samples * sampled.to.points(extents=extents)(style=dict(color='r'))\n",
"sampling = all_samples * sampled.to.points(extents=extents).opts(style=dict(color='r'))\n",
"sampling + sampled"
]
},
Expand Down
2 changes: 1 addition & 1 deletion examples/user_guide/14-Large_Data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
"\n",
"from datashader.colors import Sets1to3 # default datashade() and shade() color cycle\n",
"color_key = list(enumerate(Sets1to3[0:num_ks]))\n",
"color_points = hv.NdOverlay({k: hv.Points([0,0], label=str(k))(style=dict(color=v)) for k, v in color_key})\n",
"color_points = hv.NdOverlay({k: hv.Points([0,0], label=str(k)).opts(style=dict(color=v)) for k, v in color_key})\n",
"\n",
"color_points * gaussspread"
]
Expand Down
12 changes: 6 additions & 6 deletions examples/user_guide/Deploying_Bokeh_Apps.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
" label = 'Mean x, y: %.3f, %.3f' % tuple(arr.mean(axis=0))\n",
" else:\n",
" label = 'No selection'\n",
" return points.clone(arr, label=label)(style=dict(color='red'))\n",
" return points.clone(arr, label=label).opts(style=dict(color='red'))\n",
"\n",
"# Combine points and DynamicMap\n",
"layout = points + hv.DynamicMap(selected_info, streams=[selection])\n",
Expand Down Expand Up @@ -285,7 +285,7 @@
"\n",
"renderer = hv.renderers('bokeh')\n",
"\n",
"points = hv.Points(np.random.randn(1000,2 ))(plot=dict(tools=['box_select', 'lasso_select']))\n",
"points = hv.Points(np.random.randn(1000,2 )).opts(plot=dict(tools=['box_select', 'lasso_select']))\n",
"selection = hv.streams.Selection1D(source=points)\n",
"\n",
"def selected_info(index):\n",
Expand All @@ -294,7 +294,7 @@
" label = 'Mean x, y: %.3f, %.3f' % tuple(arr.mean(axis=0))\n",
" else:\n",
" label = 'No selection'\n",
" return points.clone(arr, label=label)(style=dict(color='red'))\n",
" return points.clone(arr, label=label).opts(style=dict(color='red'))\n",
"\n",
"layout = points + hv.DynamicMap(selected_info, streams=[selection])\n",
"\n",
Expand Down Expand Up @@ -336,7 +336,7 @@
"source": [
"def sine(frequency, phase, amplitude):\n",
" xs = np.linspace(0, np.pi*4)\n",
" return hv.Curve((xs, np.sin(frequency*xs+phase)*amplitude))(plot=dict(width=800))\n",
" return hv.Curve((xs, np.sin(frequency*xs+phase)*amplitude)).opts(plot=dict(width=800))\n",
"\n",
"ranges = dict(frequency=(1, 5), phase=(-np.pi, np.pi), amplitude=(-2, 2), y=(-2, 2))\n",
"dmap = hv.DynamicMap(sine, kdims=['frequency', 'phase', 'amplitude']).redim.range(**ranges)\n",
Expand Down Expand Up @@ -498,7 +498,7 @@
"def sine(counter):\n",
" phase = counter*0.1%np.pi*2\n",
" xs = np.linspace(0, np.pi*4)\n",
" return hv.Curve((xs, np.sin(xs+phase)))(plot=dict(width=800))\n",
" return hv.Curve((xs, np.sin(xs+phase))).opts(plot=dict(width=800))\n",
"\n",
"dmap = hv.DynamicMap(sine, streams=[hv.streams.Counter()])\n",
"\n",
Expand Down Expand Up @@ -564,7 +564,7 @@
"# Create the holoviews app again\n",
"def sine(phase):\n",
" xs = np.linspace(0, np.pi*4)\n",
" return hv.Curve((xs, np.sin(xs+phase)))(plot=dict(width=800))\n",
" return hv.Curve((xs, np.sin(xs+phase))).opts(plot=dict(width=800))\n",
"\n",
"stream = hv.streams.Stream.define('Phase', phase=0.)()\n",
"dmap = hv.DynamicMap(sine, streams=[stream])\n",
Expand Down
8 changes: 4 additions & 4 deletions examples/user_guide/Plotting_with_Bokeh.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@
"xs = np.linspace(0, np.pi*4, 100)\n",
"data = (xs, np.sin(xs))\n",
"\n",
"(hv.Curve(data)(style=curve_opts) +\n",
" hv.Points(data)(style=point_opts) +\n",
" hv.Text(6, 0, 'Here is some text')(style=text_opts))"
"(hv.Curve(data).opts(style=curve_opts) +\n",
" hv.Points(data).opts(style=point_opts) +\n",
" hv.Text(6, 0, 'Here is some text').opts(style=text_opts))"
]
},
{
Expand Down Expand Up @@ -168,7 +168,7 @@
" ('N Ticks', {'xticks': 3}),\n",
" ('List Ticks', {'xticks': [0, 100, 300, 500]})]\n",
"\n",
"hv.Layout([points.relabel(group=group)(plot=opts)\n",
"hv.Layout([points.relabel(group=group).opts(plot=opts)\n",
" for group, opts in axes_opts]).cols(3).display('all')"
]
},
Expand Down

0 comments on commit 350b323

Please sign in to comment.