【问题标题】:Python: How do I change the colors of lines on a multi-line chart in plotly? [duplicate]Python:如何在绘图中更改多折线图上线条的颜色? [复制]
【发布时间】:2022-01-15 13:24:33
【问题描述】:

如何更改下面图表中线条的颜色?谢谢

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

【问题讨论】:

    标签: python plotly


    【解决方案1】:
    • 您尚未提供示例数据,已模拟示例代码所暗示的相同结构的数据框
    • 使用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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-18
      • 1970-01-01
      • 2020-06-09
      • 2019-10-27
      • 1970-01-01
      相关资源
      最近更新 更多