[Bokeh 2.3.1]
Hi there,
I’m using multidimensional (image)data and want to plot the different dimensions against each other. For that I use image
inside a figure
. To display the images I set bounds to disallow panning away from the image. When I change the image/dimensions I adjust the figure
's attributes aspect_ratio
and x_range.start
, x_range.end
, x_range.bounds
, same for y_range
. I also adjust the image
s datasource: dw
, dh
and image
.
Now here’s the problem: If I change the image (all of the above) and then use the boxedit tool, the bounds reset to the inital image’s bounds.
Normally I would think that I screwed up somewhere/am misusing Bokeh, but:
This does not happen if you pan around on the first image, change the image and then use the boxedit…
Either way, I could use some help (a workaround possibly).
Example code
import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import column, row
from bokeh.models import Button, DataRange1d, BoxEditTool, ColumnDataSource
from bokeh.plotting import figure
xs = 10
ys = 10
data = np.random.rand(xs, ys)
source = ColumnDataSource(data=dict(image=[data], dw=[xs], dh=[ys]))
x_range = DataRange1d(start=0, end=xs, min_interval=1, range_padding=0, bounds=(0, xs))
y_range = DataRange1d(start=0, end=ys, min_interval=1, range_padding=0, bounds=(0, ys))
plot = figure(tools=["pan"], toolbar_location="above", x_range=x_range, y_range=y_range, aspect_ratio=xs/ys)
img = plot.image(source=source, x=0, y=0, dw="dw", dh="dh")
roi = plot.rect('x', 'y', 'width', 'height',
source=ColumnDataSource(data=dict(x=[], y=[], width=[], height=[])))
be = BoxEditTool(num_objects=1, renderers=[roi])
plot.add_tools(be)
def set_image():
new_img = np.random.rand(13, 5)
sx, sy = new_img.shape
source.data['dw'] = [sx]
source.data['dh'] = [sy]
source.data['image'] = [new_img]
plot.aspect_ratio = sx/sy
plot.x_range.start = 0
plot.x_range.end = sx
plot.x_range.bounds = (0, sx)
plot.y_range.start = 0
plot.y_range.end = sy
plot.y_range.bounds = (0, sy)
btn = Button(name="New Image")
btn.on_click(set_image)
curdoc().add_root(row(plot, btn))
Edit: Clip that shows my problem Gyazo
Clip that shows a way to avoid the problem with panning first: Gyazo