【问题标题】:(Python) Plotly Scatter - Specify Line Color with Integer Value(Python) Plotly Scatter - 用整数值指定线条颜色
【发布时间】:2019-11-20 13:29:56
【问题描述】:

Plotly 允许用户根据整数值指定标记散点图的颜色,例如:

go.Scatter(x=x,
           y=y,
           mode='markers',
           marker=dict(color=i))

其中 i 是一个整数。但是,如果我想指定线条的颜色,以下都不起作用:

go.Scatter(x=x,
           y=y,
           mode='lines',
           marker=dict(color=i))

go.Scatter(x=x,
           y=y,
           mode='lines',
           line=dict(color=i))

如何使用整数指定 Plotly 线的颜色?

【问题讨论】:

    标签: colors plotly scatter-plot plotly-python


    【解决方案1】:

    在您的情况下,color 必须是数字数组,而不是数字。

    根据Plotly documentation

    设置标记颜色。它接受特定颜色或数字数组,这些数字映射到相对于数组的最大值和最小值或相对于marker.cminmarker.cmax(如果已设置)的色阶。

    例子:

    import plotly.graph_objects as go
    
    fig = go.Figure(data=go.Scatter(
        x=[1, 2, 3, 4],
        y=[10, 11, 12, 13],
        mode='markers',
        marker=dict(size=[40, 60, 80, 100],
                    color=[0, 1, 2, 3])
    ))
    
    fig.show()
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-16
      • 2020-02-21
      • 2023-03-29
      • 2021-10-31
      • 1970-01-01
      • 1970-01-01
      • 2021-01-11
      • 1970-01-01
      相关资源
      最近更新 更多