1

我正在尝试将抖动添加到绘图中,以便重复值不会相互重叠并且代码运行良好,但显示 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"
4

1 回答 1

2

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

f.circle(x={'field': "x", 'transform': Jitter(width=0.4)}, y="y", source=data)
于 2017-07-28T19:31:43.223 回答