散景抖动不起作用



我正在尝试向绘图添加抖动,以便重复值不会相互重叠并且代码运行良好,但显示 HTML 文件给我一个错误。

代码:

from bokeh.plotting import figure
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource, Jitter
x = [1,2,3,4,5,3,3,3]
y = [1,2,2,4,5,2,3,3]
data = ColumnDataSource(dict(x=x, y=y))
output_file("iris.html")
f=figure()
f.plot_width = 800
f.plot_height = 800
f.sizing_mode="stretch_both"
f.circle(x={'value': "x", 'transform': Jitter(width=0.4)}, y="y", source=data)
show(f)

打开 HTML 文件时出现的错误是:

Bokeh Error
Number property 'x' given invalid value: "x"

这不是一个很好的错误消息,但问题是您正在尝试转换数据源的值"x"而不是字段"x"。它应该工作:

f.circle(x={'field': "x", 'transform': Jitter(width=0.4)}, y="y", source=data)

最新更新