Python bokeh: Multiple color segments on same line
<p>I am using python 3.5 and bokeh 0.12.1, and I am trying to plot a simple line with multiple colors on separate segments. Basically I want the line to have different colors based on a column value.
Here is a simplified version of my code:</p>

<pre><code>import numpy as np
from numpy import vectorize
import pandas as pd
from bokeh.plotting import figure, show, output_file


def f(x):
    return 2 * x


def color(x):
    if x &lt; 20:
        return 0
    if 20 &lt;= x &lt; 60:
        return 1
    if 60 &lt;= x &lt; 80:
        return 0
    else:
        return 1


v_color = vectorize(color)
x = np.arange(0, 100, 1)
data = {'x': x, 'y': f(x), 'colors': v_color(x)}
df = pd.DataFrame(data=data)
# print(df)

p = figure(title="Line example")

p.line(df['x'], df['y'], legend="y=f(x)",
       # line_color="tomato",
       line_color="olivedrab",
       line_width=2)

p.legend.location = "top_left"

output_file("basic_line_test.html", title="line plot example")

show(p)  # open a browser
</code></pre>

<p>Basically the line should have one color, let's say 'olivedrab' when the column 'colors' is 0 and 'tomato' when the value is 1.
How can I do that?</p>