散景四边形 'got multiple values' 错误

Bokeh quads 'got multiple values' error

我正在尝试使用 Bokeh 绘制四边形图。给我错误的代码结构与我下面的非常相似。

my_dict = {...} # has the following keys [left, right, bottom, top, color]

p = figure(width = 800, height = 800)

source= ColumnDataSource(data = my_dict)

p.quad(source,
       top="top",
       bottom = "bottom",
       left = "left",
       right = "right",
       color = "color")  

这会产生以下错误:

TypeError: quad() got multiple values for argument 'left'

我的 dict 中所有列表的长度都相等。我检查使用:

for key in my_dict.keys():
  print(len(my_dict[key ]))

我不确定如何进行。我还对 'left' 的每个条目进行了类型检查,看看它是否抱怨输入不一致。有什么想法吗?

quad 的第一个参数不是数据源:

http://docs.bokeh.org/en/latest/docs/reference/plotting.html#bokeh.plotting.figure.Figure.quad

它是 left,这意味着在上面的代码中,您将 left 的值作为位置参数传递(但将 source 作为值传递)作为以及将 left 作为关键字参数传递。这正是会导致 Python 抱怨的情况:

>>> def foo(arg): pass
...
>>> foo(10, arg=20)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: foo() got multiple values for keyword argument 'arg'

您需要将 source 作为关键字参数传递(如所有示例所示):

p.quad(top="top",
       bottom="bottom",
       left="left",
       right="right",
       color="color",
       source=source)