Trying to implement the following code example as a line plot (mode="lines"
), whilst keeping the conditional coloring working. Conditional color formatting does not come through with 'line'.
import plotly.graph_objects as go
import pandas as pd
df = pd.DataFrame({
"x": [1, 2, 3, 4, 5, 6, 7],
"y": [200, 400, 100, 800, 500, 200, 1100]
})
# Condition
colors = ["blue" if y > 600 else "red" for y in df["y"]]
# Scatter plot with conditional colors
fig = go.Figure(
go.Scatter(
x=df["x"],
y=df["y"],
mode="markers", # coloring does not work with mode="lines"
marker=dict(color=colors)
)
)
fig.show()
I would rather keep it all in one Scatter, as opposed to subplots with make_subplots.
UPDATE when using when using mode="lines" AND plotly 5.11.0, no error message is through, however coloring doesn't come through:
I'm trying to make the marked lines red in this case as those markers are greater than 600.