如何在bokeh中为“ X”轴分配多种颜色?

时间:2019-04-16 00:05:02

标签: python bokeh

我想制作一个在bokeh中看起来像这样的折线图:

https://i.imgur.com/X6A049C.png

如何为bokeh中的tweet_bss.py设置多种颜色?

我尝试使用X-axisp.xaxis.axis_line_color,但是它们不允许我将多个颜色分配给单个轴。

如何获得所需的结果?

谢谢。

1 个答案:

答案 0 :(得分:1)

我认为没有Bokeh函数可以执行此操作,但是您可以自己绘制它。

#!/usr/bin/python3
from bokeh.plotting import figure, show
from bokeh.models import LabelSet, ColumnDataSource

p = figure(plot_width=400, plot_height=400, x_range=(-1.5, 9.5), y_range=(-1.5, 9.5))
p.circle([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], size=20, color="navy", alpha=0.5)
p.xaxis.visible = False
p.yaxis.visible = False
p.xgrid.grid_line_color = None
p.ygrid.grid_line_color = None
p.multi_line(xs=[[0, 3], [3, 6], [6, 9], [0, 0], [0, 0], [0, 0]], ys=[[0, 0], [0, 0], [0, 0], [0, 3], [3, 6], [6, 9]], color=['green', 'yellow', 'red', 'green', 'yellow', 'red'], line_width=2)
source = ColumnDataSource({'x':[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1], 'y':[-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,], 'text':['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9']})
labels = LabelSet(x='x', y='y', text='text', source=source, x_offset=-10, y_offset=-10)
p.add_layout(labels)

show(p)

enter image description here