Brian Keats
Brian Keats

Reputation: 151

Is there a way to automatically set colors in 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

Upvotes: 7

Views: 5582

Answers (1)

v.coder
v.coder

Reputation: 1932

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]) 

Upvotes: 12

Related Questions