3

How do I change the colors of the lines in the plotly chart below? Thanks

import plotly.express as px

# forecast_eval is a dataframe with an actual number, a forecast 
# number, and upper and lower forecast bounds

# Draw a line chart using 4 columns forecast_eval.columns[2:6]
eval_line = px.line(forecast_eval, x='ds', y=forecast_eval.columns[2:6], 
title='Forecast')

eval_line

Line chart

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

4
  • you have not provided sample data, have simulated a dataframe of same structure implied by sample code
  • simple case of using color_discrete_sequence
import plotly.express as px
import numpy as np
import pandas as pd

# forecast_eval is a dataframe with an actual number, a forecast
# number, and upper and lower forecast bounds

forecast_eval = pd.concat(
    [
        pd.DataFrame({"ds": np.linspace(0, 100, 1000)}),
        pd.DataFrame(
            np.random.uniform(np.linspace(0, 10**4, 5), np.linspace(1, 2*10**4, 5), [1000, 5])
        ),
    ],
    axis=1,
)

# Draw a line chart using 4 columns forecast_eval.columns[2:6]
eval_line = px.line(
    forecast_eval,
    x="ds",
    y=forecast_eval.columns[2:6],
    title="Forecast",
    color_discrete_sequence=["yellow", "blue", "pink", "skyblue"],
)

eval_line

enter image description here

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Rob Raymond
  • 29,118
  • 3
  • 14
  • 30