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

Regrid doc elaboration for image data #3911

Merged
merged 10 commits into from
Aug 17, 2019
30 changes: 29 additions & 1 deletion examples/user_guide/15-Large_Data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,35 @@
"source": [
"In all three of the above plots, `rasterize()` is being called to aggregate the data (a large set of x,y locations) into a rectangular grid, with each grid cell counting up the number of points that fall into it. In the plot on the left, only `rasterize()` is done, and the resulting numeric array of counts is passed to Bokeh for colormapping. Bokeh can then use dynamic (client-side, browser-based) operations in JavaScript, allowing users to have dynamic control over even static HTML plots. For instance, in this case, users can use the Box Select tool and select a range of the histogram shown, dynamically remapping the colors used in the plot to cover the selected range.\n",
"\n",
"The other two plots should be identical. In both cases, the numerical array output of `rasterize()` is mapped into RGB colors by Datashader itself, in Python (\"server-side\"), which allows special Datashader computations like the histogram-equalization in the above plots and the \"spreading\" discussed below. The `shade()` and `datashade()` operations accept a `cmap` argument that lets you control the colormap used, which can be selected to match the HoloViews/Bokeh `cmap` option but is strictly independent of it. See ``hv.help(rasterize)``, ``hv.help(shade)``, and ``hv.help(datashade)`` for options that can be selected, and the [Datashader web site](http://datashader.org) for all the details. You can also try the lower-level ``hv.aggregate()`` (for points and lines) and ``hv.regrid()` (for image/raster data) operations, which may provide more control."
"The other two plots should be identical. In both cases, the numerical array output of `rasterize()` is mapped into RGB colors by Datashader itself, in Python (\"server-side\"), which allows special Datashader computations like the histogram-equalization in the above plots and the \"spreading\" discussed below. The `shade()` and `datashade()` operations accept a `cmap` argument that lets you control the colormap used, which can be selected to match the HoloViews/Bokeh `cmap` option but is strictly independent of it. See ``hv.help(rasterize)``, ``hv.help(shade)``, and ``hv.help(datashade)`` for options that can be selected, and the [Datashader web site](http://datashader.org) for all the details. The lower-level `aggregate()` gives more control over how the data is aggregated.\n",
joelostblom marked this conversation as resolved.
Show resolved Hide resolved
"\n",
"Since datashader only sends the data currently in view to the plotting backend, the default behavior is to rescale colormap to the range of the visible data as the zoom level changes. This behavior may not be desirable when working with images; to instead use a fixed colormap range, the `clim` parameter can be passed to the `bokeh` backend via the `opts()` method."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"n = 10_000\n",
"\n",
"# Strong signal on top\n",
"rs = np.random.RandomState(101010)\n",
"x = rs.pareto(n, n)\n",
"y = x + rs.standard_normal(n)\n",
"img1, *_ = np.histogram2d(x, y, bins=60)\n",
"\n",
"# Weak signal in the middle\n",
"x2 = rs.standard_normal(n)\n",
"y2 = 5 * x + 10 * rs.standard_normal(n)\n",
"img2, *_ = np.histogram2d(x2, y2, bins=60)\n",
"\n",
"img = img1 + img2\n",
"hv_img = hv.Image(img).opts(active_tools=['wheel_zoom'])\n",
"auto_scale_grid = rasterize(hv_img).opts(title='Automatic color range rescaling')\n",
"fixed_scale_grid = rasterize(hv_img).opts(title='Fixed color range', clim=(img.min(), img.max()))\n",
"auto_scale_grid + fixed_scale_grid"
]
},
{
Expand Down