Python Bokeh - 可以混合使用数据坐标和像素坐标进行绘图

Python Bokeh - Possibility to use a blend of data coordinate and pixel coordinate for plot

有没有一种方法可以用作输入,例如,圆圈根据输入数据为 x 坐标绘制坐标,并作为 y 坐标从图表顶部或底部的像素输入?

有点像matplolib的混合变换?

或者,将数据坐标转换为像素坐标会很容易,但前提是我可以找到 y_range 值?我尝试了 figure.y_range.start 但 return 没有任何效果

无法直接使用屏幕 space 坐标定位字形。事实证明,同时支持作为 Bokeh 核心功能的所有命中测试机制太难了。我可以想象有两种可能的解决方法。

首先是使用某种Annotation。注释 可以 定位在屏幕坐标中(因为它们不参与命中测试)。目前没有 "circle" 注释,但也许框或多边形注释可以满足您的需要。 BoxAnnotation 在用户指南中有一个部分,多边形注释类似:

https://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#box-annotations

或者,您可以创建第二个 "extra range" 作为屏幕(像素)单位的代理。一个例子在这里:

from bokeh.models import Range1d
from bokeh.plotting import figure, show, output_file

output_file("foo.html")

p = figure()

# this will only work for fixed layout plots, and you'll have to tune 
# the 'end' property to match your plot dimensions
p.extra_y_ranges = {"foo": Range1d(start=0, end=520)}

p.circle([10, 20, 30], [20, 260, 500], size=10, y_range_name="foo")

show(p)

当绘图内部尺寸发生变化时,现在也有回调。在可调整大小的图的情况下,您可以将其扩展为更多 robust/sophisticated。为这些内部绘图维度添加回调的方式是这样的:

p.on_change("inner_width", some_callback)
p.on_change("inner_height", some_callback)

用于 python(服务器)回调。使用 js_on_change 进行 CustomJS 回调。