Hi there, I’ve been plotting map data using holoviews and geoviews with the bokeh backend.
Bokeh has a zoom tool called BoxZoomTool
, which allows drawing a rectangle to zoom in. Setting the kwarg match_aspect=True
results in maintaining the aspect ratio, which is meaningful when working with maps. Apparently, holoviews/geoviews doesn’t properly use pass the BoxZoomTool
to bokeh as match_aspect=True
does not have any effect.
Examples:
Working BoxZoomTool
with native bokeh only (version 3.4.1 and 3.3.4, both working as expected)
import bokeh
from bokeh.plotting import figure, show
from bokeh.models import BoxZoomTool
print(f"{bokeh.__version__=}")
fruits = ['Apples', 'Pears', 'Nectarines', 'Plums', 'Grapes', 'Strawberries']
counts = [5, 3, 4, 2, 4, 6]
box_zoom = BoxZoomTool(match_aspect=True)
p = figure(x_range=fruits, height=350, title="Fruit Counts",
toolbar_location=None, tools=[box_zoom])
p.vbar(x=fruits, top=counts, width=0.9)
p.xgrid.grid_line_color = None
p.y_range.start = 0
show(p)
Non-working holoviews code (version 1.18.3)
import numpy as np
import holoviews as hv
from bokeh.models import BoxZoomTool
hv.extension("bokeh")
print(f"{hv.__version__=}")
x,y = np.mgrid[-50:51, -50:51] * 0.1
box_zoom = BoxZoomTool(match_aspect=True)
img = hv.Image(np.sin(x**2+y**2), bounds=(-1,-1,1,1))
(img.relabel('Image') * img.sample(x=0).relabel('Cross-section')).opts(
tabs=True,
tools=[box_zoom])