Reputation: 12697
I'd like to add color to a single line plot depending on an array of values.
from bokeh.plotting import figure, show
xs=list(range(1000))
ys=[x**2 for x in xs]
cs=xs
fig=figure()
fig.line(xs, ys)
show(fig)
How can I add a continous color determined by a palette and the numeric values of cs
? I've seen a LinearColorMapper
, but I don't know how to apply it here.
Upvotes: 0
Views: 502
Reputation: 34568
As of Bokeh 1.0.4
varying the color along a single line is not supported. The HTML canvas that Bokeh renders to only supports lines with a single color, so accordingly, Bokeh only supports this as well. I'm not aware of any existing issue covering this, so certainly feel free to make a feature request if you are inclined.
Depending on exactly what you want to accomplish, it might be possible to use multi_line
or segments
to approximate this, by having many segments that each have a different color. However, results may not be perfect, as drawing individual segments means that nice line joins will not happen.
Alterntatively, Bokeh is extensible, so if you are aware of some third-party JS library that can draw these kinds of lines on an HTML canvas, you could hook that up to python code using a Bokeh extension.
Upvotes: 3