我正在用一个 ColumnDataSource
在订单方面,一旦绘制了圆圈,我也绘制了一个 Multiline 字形。我为这个字形使用了另一个来源。
字形绘制正确,但它们不符合我绘制它们的顺序。我想在图的顶部绘制 Multiline 以使其始终可见。
from bokeh.plotting import figure
from bokeh.models.sources import ColumnDataSource, CDSView
from bokeh.models.filters import IndexFilter
from bokeh.palettes import Reds3
from bokeh.io import curdoc
ml_source = ColumnDataSource(data=dict(
colors=[Reds3[0], Reds3[1]],
xs=[[1, 20, 30, 50], [24, 25, 36, 57]],
ys=[[4, 20, 50, 50], [10, 25, 35, 60]],
))
source = ColumnDataSource(data=dict(
x=[7, 8, 9, 10, 15, 30, 55, 23, 50],
y=[10, 8, 9, 20, 15, 30, 55, 23, 50],
))
plot = figure(
width=500,
height=500,
toolbar_location='left',
tools='pan,wheel_zoom,tap,lasso_select',
output_backend='webgl',
)
plot.circle(
x='x',
y='y',
radius=3,
fill_color='blue',
line_color=None,
source=source,
)
ml_prof_line = plot.multi_line(
xs='xs',
ys='ys',
source=ml_source,
color='colors',
line_width=5,
line_alpha=1.0,
)
curdoc().add_root(plot)
我用 bokeh serve --show example.py 启动它
这是结果:
我尝试过对两者使用相同的来源,但结果是一样的。
有什么问题吗?这是预期的行为吗?
我认为 Multiline 存在错误,因为如果我按预期使用该行
plot.line(
x='x',
y='y',
source=source,
color='red',
line_width=5,
line_alpha=1.0,
)
更新
- 我已将此张贴在 issue 上
- 最后它是另一个问题的重复:Mixed canvas and webgl glyphs are painted in wrong z-order
请您参考如下方法:
我认为我们有这种行为是因为圆圈是标记,而线条是 Bokeh 模型方面的字形。将圆更改为具有相同宽度和高度的椭圆,因为椭圆也是一个字形。所以只需将 plot.circle() 替换为
plot.ellipse(
x='x',
y='y',
width=3,
height=3,
color='blue',
source=source
)
