0

我正在使用 plotly 从 Pandas 数据框中绘制散点图并将它们嵌入到 html 中。我已经想出了如何定义数据、布局和生成嵌入所需的代码,但我正在努力寻找改变绘图风格的方法。

具体来说,我想:

  • 更改线条样式(例如,从实线变为虚线或点线......我想出了如何从线变为标记)
  • 更改标记样式和颜色
  • 指定每条线或标记系列的颜色

下面是我的代码片段,显示了绘图部分。这段代码在我的脚本中运行良好,我只是不知道如何修改外观。任何帮助都会很棒!

谢谢 :)

layout = go.Layout(
    title="This is the title",
    xaxis=dict(
        title="x-axis label",
        autorange=True,
        showgrid=True,
        zeroline=False,
        showline=False,
        ticks='',
        showticklabels=True,
    ),
    yaxis=dict(
        title="y-axis label",
        autorange=True,
        showgrid=True,
        zeroline=False,
        showline=False,
        ticks='',
        showticklabels=True
    ),
    width=800,height=550
)

data=[
    go.Scatter(
        x=df["Timestamp"],
        y=df["Conditions1"],
        name="Trace 1",
        mode="markers",
        ),
    go.Scatter(
        x=df["Time"],
        y=df["Conditions2"],
        name="Trace 2",
        mode="markers"
        )
    ]

fig1 = go.Figure(data=data, layout=layout)

plot1 = plotly.offline.plot(fig1,
                            config={"displaylogo": False}, 
                            show_link=False, 
                            include_plotlyjs=True,
                            output_type='div')
4

1 回答 1

1

如果你希望你的情节有你应该设置的点和线mode="markers+lines",无论哪种方式,你都可以在散点图中修改markerline对象:

go.Scatter(
    x=df["Time"],
    y=df["Conditions2"],
    name="Trace 2",
    mode="markers+lines",
    marker=dict(
        color="red", # or "rgb(255,0,0)" or "#ff0000" or even another pandas column
        size=7,
        symbol="cross",
        line=dict(
            # you can add here the properties for the outline of the markers
            color="green",
            width=1,
        )
    )
    line=dict(
        shape="linear", # or "spline" for instance, for a curvy line
        dash="dash", # or "dot", "dashdot", etc.
        color="blue",
        width=3,
    )
)

您可以在标记线条参考中看到所有可用选项。

于 2019-02-13T11:47:24.600 回答