{ "cells": [ { "cell_type": "markdown", "id": "df229fb9-0a56-47b4-a8d2-72cab8782624", "metadata": {}, "source": [ "#### **Title**: Sizebar\n", "\n", "**Dependencies**: Bokeh >= 3.8.0\n", "\n", "**Backends**: [Bokeh](./Sizebar.ipynb)\n", "\n", "The `sizebar` feature makes a sizebar on the element to help gauge the size of circles on a plot. For this to work it need to have `radius` option set." ] }, { "cell_type": "code", "execution_count": null, "id": "1cee420f-3ad1-4b0c-ae66-b26d726d7a0a", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "\n", "import holoviews as hv\n", "from holoviews.plotting.util import rgb2hex\n", "\n", "rng = np.random.default_rng(1)\n", "N = 100\n", "x = rng.random(size=N) * 100\n", "y = rng.random(size=N) * 100\n", "radii = rng.random(size=N) * 10\n", "colors = np.array(\n", " [(r, g, 150) for r, g in zip(50 + 2 * x, 30 + 2 * y)], dtype=np.uint8\n", ")\n", "colors = list(map(rgb2hex, colors / 256))\n", "\n", "hv.extension(\"bokeh\")\n", "\n", "points = hv.Points((x, y, radii, colors), vdims=[\"radii\", \"colors\"])\n", "points.opts(\n", " color=\"colors\", radius=\"radii\", alpha=0.6, height=500, width=500, sizebar=True\n", ")" ] }, { "cell_type": "markdown", "id": "d58cb23b-206b-4368-aed7-b083a7766320", "metadata": {}, "source": [ "Zoom in and out to see the sizebar dynamically adjust." ] }, { "cell_type": "markdown", "id": "39af797f-4ea2-449b-96c7-eb7d0da8394e", "metadata": {}, "source": [ "### Customization\n", "\n", "In the plot above, you can see that we applied the sizebar. Below are further customization options for the sizebar:\n", "\n", "- The `sizebar_location` parameter defines the positioning anchor for the sizebar. Options include `\"above\"`, `\"below\"`, `\"left\"`, `\"right\"`, and `\"center\"`.\n", "- The `sizebar_orientation` parameter controls whether the sizebar is displayed `\"horizontal\"` (default) or `\"vertical\"`.\n", "- The `sizebar_color` parameter specifies the glyph color in the sizebar (default: `\"black\"`).\n", "- The `sizebar_alpha` parameter sets the transparency of the sizebar glyph, between `0` and `1` (default: `0.6`).\n", "- The `sizebar_bounds` parameter can be used to manually set the bounds of the sizebar as a tuple `(min, max)`. By default, `None` lets the bounds be determined automatically from the data.\n", "- The `sizebar_opts` parameter enables specific styling options for the sizebar. See the [Bokeh SizeBar documentation](https://docs.bokeh.org/en/latest/docs/reference/models/annotations.html#bokeh.models.SizeBar) for available options.\n", "\n", "All these parameters are only utilized if `sizebar=True` is set in `.opts()`." ] }, { "cell_type": "code", "execution_count": null, "id": "0ab063b3-d1cb-40b4-9fa7-a5860932c16d", "metadata": {}, "outputs": [], "source": [ "points.clone().opts(\n", " sizebar_location=\"right\",\n", " sizebar_orientation=\"vertical\",\n", " sizebar_color=\"red\",\n", " sizebar_alpha=1,\n", ")" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 5 }