Pandas 图表使用 plotly.graph_objects 不允许 'c' 或 'color' 属性

Pandas chart using plotly.graph_objects DO NOT ALLOW FOR 'c' or 'color' ATTRIBUTE

我正在向 OHLV 中添加折线图,但我无法为它们着色。

def chart_ema(histo_df:pd.DataFrame,
              ):
    # https://plotly.com/python/ohlc-charts/
    # THAT PARTS ADD THE OHLC CHART

    fig = go.Figure(data=go.Ohlc(x=histo_df.index,
                                 open=histo_df['open'],
                                 high=histo_df['high'],
                                 low=histo_df['low'],
                                 close=histo_df['close'],
                                 name='ohlc'
                                 ))
    # THAT PARTS ADD THE 2 EMA LINE CHARTS
    for column_name in histo_df.columns:
        if 'ema' in column_name and 'cloud' not in column_name:
            fig.add_scatter(x=histo_df.index,
                            y=histo_df[column_name],
                            name=column_name,
                            color='b'
                            # fillcolor='orange', # does not work either

                            )

    fig.show()

当我使用 'color' 作为 'figg.add_scatter' 属性时,上述代码失败: 给出的错误是:

...

Did you mean "fill"?

Bad property path:

当我没有指定散点线的颜色时,程序运行正常。

下面是一个数据样本:

trade_datetime,open,high,low,close,volume,ema_160,ema_50,cloud_50_160
2022-04-04 08:00:00+00:00,452.530000,453.290000,452.100000,452.430000,0,452.43,452.43,0.0
2022-04-04 08:15:00+00:00,452.450000,452.700000,452.310000,452.700000,0,452.43335403726707,452.4405882352941,0.007234198027049388
2022-04-04 12:00:00+00:00,453.440000,454.160000,452.160000,453.630000,0,452.61217633267256,452.9215287670084,0.30935243433583537
2022-04-04 12:15:00+00:00,453.630000,454.000000,453.610000,453.680000,0,452.6254412229499,452.9512727369297,0.3258315139797787
2022-04-04 12:30:00+00:00,453.710000,453.870000,453.480000,453.490000,0,452.6361810835343,452.97239929626585,0.33621821273152364
2022-04-04 12:45:00+00:00,453.460000,453.460000,452.860000,452.970000,0,452.6403279023724,452.9723052062162,0.3319773038438143
2022-04-04 13:00:00+00:00,452.960000,453.430000,452.950000,453.430000,0,452.65013749364726,452.99025402165876,0.3401165280114924
2022-04-04 13:15:00+00:00,,,,,0,452.65013749364726,452.99025402165876,0.3401165280114924
2022-04-04 13:30:00+00:00,453.000000,453.410000,452.260000,453.190000,3501932,452.6569271560714,452.99839388973334,0.3414667336619459
2022-04-04 13:45:00+00:00,453.190000,454.700000,452.650000,454.520000,3078587,452.6800709181078,453.05806471758694,0.3779937994791567
2022-04-04 14:00:00+00:00,454.500000,454.680000,454.000000,454.140000,2709000,452.6982066831002,453.1004935521914,0.40228686909119915

我想在下面的示例中选择 'ema_160' 和 'ema_50' 行的颜色:

谢谢

我使用: * Pycharm * Windows 10 * Python 3.7.9 我尝试了以下网址但没有成功:

Series plot pandas color

graph_objects中的颜色规范是以字典的形式完成的,具有各种设置。如果不需要,就用单一的颜色。

def chart_ema(histo_df:pd.DataFrame,):
    # https://plotly.com/python/ohlc-charts/
    # THAT PARTS ADD THE OHLC CHART

    fig = go.Figure(data=go.Ohlc(x=histo_df.index,
                                 open=histo_df['open'],
                                 high=histo_df['high'],
                                 low=histo_df['low'],
                                 close=histo_df['close'],
                                 name='ohlc'
                                 ))
    #fig.update_layout(rangeslider=dict(visible=False))
    # THAT PARTS ADD THE 2 EMA LINE CHARTS
    for column_name in histo_df.columns:
        if 'ema' in column_name and 'cloud' not in column_name:
            fig.add_scatter(x=histo_df.index,
                            y=histo_df[column_name],
                            name=column_name,
                            line=dict(color='royalblue' if column_name == 'ema_50' else 'red', dash='dash'),
                            mode='lines'
                            # fillcolor='orange', # does not work either
                            )

    fig.update_layout(autosize=False,
                      width=800,
                      height=600
                     )
    fig.show()

chart_ema(histo_df)