简体   繁体   English

如何为散景中的“X”轴分配多种颜色?

[英]How do I assign multiple colors to the "X" axis in bokeh?

I'd like to make a line graph that looks like this in bokeh:我想在散景中制作一个如下所示的折线图:

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

How do I set multiple colours for the X-axis in bokeh?如何在散景中为X-axis设置多种颜色?

I tried to use p.xaxis.axis_line_color and p.xaxis.bounds but they don't allow me to assign multiple colours to a single axis.我尝试使用p.xaxis.axis_line_colorp.xaxis.bounds但它们不允许我为单个轴分配多种颜色。

How can I get the desired result?我怎样才能得到想要的结果?

Thanks.谢谢。

I don't think there is a Bokeh function to do this, but you can draw it yourself.我认为没有散景功能可以做到这一点,但您可以自己绘制。

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

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM