Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to automatically set colors in bokeh?

Tags:

python

bokeh

Is there a way in Bokeh to automatically set a new color for each line in a plot? Something like 'hold all' in matlab.

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
like image 542
Brian Keats Avatar asked Jan 03 '23 09:01

Brian Keats


1 Answers

It can be done by selecting the colors from palette and setting different for each line plot:

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]) 
like image 196
v.coder Avatar answered Jan 05 '23 22:01

v.coder