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_locationparameter defines the positioning anchor for the sizebar. Options include"above","below","left","right", and"center".The
sizebar_orientationparameter controls whether the sizebar is displayed"horizontal"(default) or"vertical".The
sizebar_colorparameter specifies the glyph color in the sizebar (default:"black").The
sizebar_alphaparameter sets the transparency of the sizebar glyph, between0and1(default:0.6).The
sizebar_boundsparameter can be used to manually set the bounds of the sizebar as a tuple(min, max). By default,Nonelets the bounds be determined automatically from the data.The
sizebar_optsparameter 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,
)
Download this notebook from GitHub (right-click to download).