如何将多个颜色指定给bokeh中的“X”轴?

2024-04-24 12:34:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我想做一个线图,在博基赫看起来是这样的:

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

如何为bokeh中的X-axis设置多种颜色?你知道吗

我试着使用p.xaxis.axis_line_colorp.xaxis.bounds,但是它们不允许我为一个轴分配多种颜色。你知道吗

我怎样才能得到想要的结果?你知道吗

谢谢。你知道吗


Tags: 颜色linebokehcolorboundsaxis线图xaxis
1条回答
网友
1楼 · 发布于 2024-04-24 12:34:14

我不认为有一个博克函数可以做到这一点,但你可以自己画。你知道吗

#!/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

相关问题 更多 >