Color change by range in line chart

Hi @gridiron9999,

It’s not possible to change the color of a line within a single scatter trace. But if you only have a few discrete colors you could probably make something work with multiple traces.

Something like

import numpy as np
import pandas as pd
import plotly.graph_objs as go
from plotly.offline import init_notebook_mode, iplot
init_notebook_mode()

xs = np.linspace(0, 20, 100)
ys = np.sin(xs) + xs*0.1
df = pd.DataFrame({'x': xs, 'y': ys})
theshhold = 1.0

fig = go.Figure()
# Full line
fig.add_scattergl(x=xs, y=df.y, line={'color': 'black'})

# Above threshhgold
fig.add_scattergl(x=xs, y=df.y.where(df.y >= 1), line={'color': 'red'})

iplot(fig)

Hope that helps!
-Jon

2 Likes