Sizebar#

Download this notebook from GitHub (right-click to download).


Title: Sizebar#

Dependencies: Bokeh >= 3.8.0

Backends: Bokeh

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.

import numpy as np

import holoviews as hv
from holoviews.plotting.util import rgb2hex

rng = np.random.default_rng(1)
N = 100
x = rng.random(size=N) * 100
y = rng.random(size=N) * 100
radii = rng.random(size=N) * 10
colors = np.array(
    [(r, g, 150) for r, g in zip(50 + 2 * x, 30 + 2 * y)], dtype=np.uint8
)
colors = list(map(rgb2hex, colors / 256))

hv.extension("bokeh")

points = hv.Points((x, y, radii, colors), vdims=["radii", "colors"])
points.opts(
    color="colors", radius="radii", alpha=0.6, height=500, width=500, sizebar=True
)

Zoom in and out to see the sizebar dynamically adjust.

Customization#

In the plot above, you can see that we applied the sizebar. Below are further customization options for the sizebar:

  • The sizebar_location parameter defines the positioning anchor for the sizebar. Options include "above", "below", "left", "right", and "center".

  • The sizebar_orientation parameter controls whether the sizebar is displayed "horizontal" (default) or "vertical".

  • The sizebar_color parameter specifies the glyph color in the sizebar (default: "black").

  • The sizebar_alpha parameter sets the transparency of the sizebar glyph, between 0 and 1 (default: 0.6).

  • 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.

  • The sizebar_opts parameter enables specific styling options for the sizebar. See the Bokeh SizeBar documentation for available options.

All these parameters are only utilized if sizebar=True is set in .opts().

points.clone().opts(
    sizebar_location="right",
    sizebar_orientation="vertical",
    sizebar_color="red",
    sizebar_alpha=1,
)
This web page was generated from a Jupyter notebook and not all interactivity will work on this website. Right click to download and run locally for full Python-backed interactivity.

Download this notebook from GitHub (right-click to download).