我正在使用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')
答案 0 :(得分:1)
如果您希望绘图具有点和线,则应设置mode="markers+lines"
,在散点图内的任何一种方式下,您都可以修改marker
和line
对象:
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,
)
)