[Bokeh 2.3.1]
Hello,
I’m changing the plot’s size dynamically. The attached ColorBar-LayoutDOM aligns correctly with the new dimensions, however its ticks do not.
Same problem if I attach the ColorBar to a dummy-plot.
How do I fix this?
Thank you in advance
Example
import numpy as np
from bokeh.io import curdoc
from bokeh.layouts import row
from bokeh.models import Button, ColumnDataSource, DataRange1d
from bokeh.plotting import figure
from bokeh.models import ColumnDataSource, LinearColorMapper
from bokeh.models import ColorBar
from bokeh.palettes import grey, turbo, inferno
xs = 10
ys = 10
data = np.random.rand(xs, ys)
source = ColumnDataSource(data=dict(image=[], dw=[], dh=[]))
plot = figure(tools=["pan"], toolbar_location="above", x_range=(0, xs), y_range=(0, ys))
plot.x_range.bounds = (0, xs)
plot.y_range.bounds = (0, ys)
img = plot.image(source=source, x=0, y=0, dw="dw", dh="dh")
color_mapper = LinearColorMapper(palette=turbo(50), low=0, high=1)
color_bar = ColorBar(color_mapper=color_mapper, label_standoff=12)
dummy = figure(height=1,
width=1,
tools=[],
toolbar_location=None,
min_border=0,
outline_line_color=None,
sizing_mode="stretch_height")
dummy.add_layout(color_bar, 'right')
plot.add_layout(color_bar, 'right')
#r = row(plot, dummy)
PREF_HEIGHT = 800
MAX_WIDTH = 1200
flip = True
def set_image():
global flip
_shape = (10, 20)
if flip:
_shape = _shape[::-1]
flip = not flip
new_img = np.random.rand(*_shape)
sy, sx = new_img.shape
x_ratio = sx/sy
height = PREF_HEIGHT
width = height*x_ratio
if width > MAX_WIDTH:
height = round(height * MAX_WIDTH/width)
width = 1200
width = round(width)
plot.min_border_left = 50
plot.min_border_bottom = 50
plot.min_border_top = 50
plot.min_border_right = 150
plot.plot_width = width + plot.min_border_left + plot.min_border_right
plot.plot_height = height + plot.min_border_bottom + plot.min_border_top
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)
source.data = dict(image=[new_img], dw=[sx], dh=[sy])
btn = Button(name="New Image")
btn.on_click(set_image)
curdoc().add_root(row(plot, btn))