在文档的例子中
from bokeh.io import show
from bokeh.models import ColumnDataSource
from bokeh.palettes import RdBu3
from bokeh.plotting import figure
c1 = RdBu3[2] # red
c2 = RdBu3[0] # blue
source = ColumnDataSource(dict(
x=[1, 2, 3, 4, 5, 6],
y=[2, 1, 2, 1, 2, 1],
color=[c1, c2, c1, c2, c1, c2],
label=['hi', 'lo', 'hi', 'lo', 'hi', 'lo']
))
p = figure(x_range=(0, 7), y_range=(0, 3), plot_height=300, tools='save')
# Note legend field matches the column in `source`
p.circle( x='x', y='y', radius=0.5, color='color', legend='label', source=source)
show(p)
有没有办法将图例中的项目顺序更改为('lo','hi')而不是('hi','lo'),而无需重新排序所有原始数组中的项目?< / p>
答案 0 :(得分:0)
此解决方法允许完成此任务:
from math import nan
from bokeh.io import show
from bokeh.models import ColumnDataSource
from bokeh.palettes import RdBu3
from bokeh.plotting import figure
c1 = RdBu3[2] # red
c2 = RdBu3[0] # blue
source = ColumnDataSource(dict(
x=[nan, nan, 1, 2, 3, 4, 5, 6],
y=[nan, nan, 2, 1, 2, 1, 2, 1],
color=[c2, c1, c1, c2, c1, c2, c1, c2],
label=['lo', 'hi', 'hi', 'lo', 'hi', 'lo', 'hi', 'lo']
))
p = figure(x_range=(0, 7), y_range=(0, 3), plot_height=300, tools='save')
# Note legend field matches the column in `source`
p.circle( x='x', y='y', radius=0.5, color='color', legend='label', source=source)
show(p)