通过 CustomJS 更新轴范围时,分类轴上的矩形字形出现意外行为 - Bokeh

Rect glyphs on a categorical axis behave unexpectedly when updating axis range via CustomJS - Bokeh

我正在用 Rect 字形和分类轴上的标签集绘制相关矩阵的热图表示。我正在尝试使用 MultiSelect 小部件动态更新当前显示的元素。

预期行为 - 当我单击按钮时,热图更新并仅显示在小部件中选取的元素(X 轴和 Y 轴标签相同)。这在大多数情况下都可以正常工作,但是

观察到的行为:如果我取消选中列表中的第一个标签,Rect 字形向右移动 1 个单位,而 LabelSet 字形显示正确。

这是一个最小的例子:

from bokeh.io import show, output_notebook
from bokeh.models.callbacks import CustomJS
from bokeh.models.glyphs import Rect
from bokeh.events import ButtonClick
from bokeh.models.widgets import MultiSelect, Button
from bokeh.models import ColumnDataSource, LabelSet
from bokeh.layouts import row, column
from bokeh.plotting import figure
output_notebook()

data = pd.DataFrame({
    'A': [0,1,2],
    'B': [3,4,5],
    'C': [6,7,8]
}, index=['A', 'B', 'C'])
data_transformed = data.stack().rename('value').reset_index()
source = ColumnDataSource(data_transformed)

p = figure(
    width=200,
    height=200,
    x_range=data_transformed.level_0.unique().tolist(),
    y_range=data_transformed.level_0.unique().tolist()[::-1],
    x_axis_location="above"
)

rect = Rect(
    x='level_0',
    y='level_1',
    width=1,
    height=1,
    fill_color='red',
    line_color='black'
)

labels = LabelSet(
    x='level_0',
    y='level_1',
    text='value',
    level='annotation',
    source=source
)
p.add_glyph(source, rect)
p.add_layout(labels)

multiselect = MultiSelect(
    title='Pick the symbols',
    value=data_transformed.level_0.unique().tolist(),
    options=data_transformed.level_0.unique().tolist(),
    height=200
)
button_callback = CustomJS(args=dict(plot=p, multiselect=multiselect), code="""

var x_range = multiselect.value.concat().sort()
var y_range = x_range.concat().reverse()

plot.x_range.factors = x_range
plot.y_range.factors = y_range

""")

button = Button(label="Calculate", button_type="primary")
button.js_on_event(ButtonClick, button_callback)
widgets = column(children=[multiselect, button])
layout = row(children=[widgets, p])


show(layout)

初始显示:

Image 1

取消选中最后一个元素并单击按钮后(此处一切正常):

Image 2

如果未选中第一个元素:

Image 3

切换到 Circle 字形后,它按预期工作:

Image 4

这是一个错误还是我做错了什么?谢谢。

我正在使用 Bokeh 2.0.2

我很确定这是一个错误。我打开了 https://github.com/bokeh/bokeh/issues/10219.