gpt4 book ai didi

python - 有没有办法在 Bokeh 中自动设置颜色?

转载 作者:行者123 更新时间:2023-12-03 20:17:43 25 4
gpt4 key购买 nike

Bokeh 中是否有办法自动为绘图中的每条线设置新颜色?在matlab中像'hold all'之类的东西。

from bokeh.plotting import figure
x= [1,2,3,4,5]
y = [1,2,3,4,5]

p = figure()
p.multi_line([x,x],[np.power(y,2),np.power(y,3)])
show(p)
# I'd like all lines to automatically be a different color, or selected from a map

p = figure()
p.line(x,np.power(y,2))
p.line(x,np.power(y,3))
# And/or this to produce lines of different color

最佳答案

可以通过从调色板中选择颜色并为每个线图设置不同的颜色来完成:

from bokeh.palettes import Dark2_5 as palette
import itertools

#colors has a list of colors which can be used in plots
colors = itertools.cycle(palette)

p = figure()
p.line(x,np.power(y,2),color=colors[0])
p.line(x,np.power(y,3),color=colors[1])

关于python - 有没有办法在 Bokeh 中自动设置颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46451217/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com