Bokeh 服务器没有为多线图显示正确的颜色
Bokeh Server doesn't show proper color for Multiple line plot
我尝试在散景服务器上绘制多条线,它几乎可以找到。
但是有一个线条颜色的问题。
我的代码如下所示,当我在 bokeh 服务器上运行时,它会引发 'Runtime error',为什么?我该如何解决?
p.multi_line('year', 'area', alpha=0.6, color=BuGn8, source=source)
RuntimeError:
Supplying a user-defined data source AND iterable values to glyph methods is
not possibe. Either:
Pass all data directly as literals:
p.circe(x=a_list, y=an_array, ...)
Or, put all data in a ColumnDataSource and pass column names:
source = ColumnDataSource(data=dict(x=a_list, y=an_array))
p.circe(x='x', y='x', source=source, ...)
bokeh.pallettes.BuGn8
不是颜色,它是颜色列表。而且,正如错误所述,您不能在使用字形方法时混合使用列表和数据源。
如果每行需要不同的颜色,可以向数据源添加另一列,并将列名传递给 multi_line
字形函数的 color
属性。
一个小例子:
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.palettes import BuGn8
p = figure()
ds = ColumnDataSource(data=dict(xs=[[1, 2, 3], [2, 3, 4]],
ys=[[3, 2, 1], [4, 3, 2]],
color=[BuGn8[0], BuGn8[-1]]))
p.multi_line(xs='xs', ys='ys', color='color', source=ds, line_width=10)
output_file("test.html")
show(p)
我尝试在散景服务器上绘制多条线,它几乎可以找到。 但是有一个线条颜色的问题。
我的代码如下所示,当我在 bokeh 服务器上运行时,它会引发 'Runtime error',为什么?我该如何解决?
p.multi_line('year', 'area', alpha=0.6, color=BuGn8, source=source)
RuntimeError:
Supplying a user-defined data source AND iterable values to glyph methods is
not possibe. Either:
Pass all data directly as literals:
p.circe(x=a_list, y=an_array, ...)
Or, put all data in a ColumnDataSource and pass column names:
source = ColumnDataSource(data=dict(x=a_list, y=an_array))
p.circe(x='x', y='x', source=source, ...)
bokeh.pallettes.BuGn8
不是颜色,它是颜色列表。而且,正如错误所述,您不能在使用字形方法时混合使用列表和数据源。
如果每行需要不同的颜色,可以向数据源添加另一列,并将列名传递给 multi_line
字形函数的 color
属性。
一个小例子:
from bokeh.io import output_file, show
from bokeh.models import ColumnDataSource
from bokeh.plotting import figure
from bokeh.palettes import BuGn8
p = figure()
ds = ColumnDataSource(data=dict(xs=[[1, 2, 3], [2, 3, 4]],
ys=[[3, 2, 1], [4, 3, 2]],
color=[BuGn8[0], BuGn8[-1]]))
p.multi_line(xs='xs', ys='ys', color='color', source=ds, line_width=10)
output_file("test.html")
show(p)