Velvet Star Monitor

Standout celebrity highlights with iconic style.

updates

Is there a way to automatically set colors in bokeh?

Writer Matthew Harrington

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

1 Answer

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

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy