我正在使用 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')
如果您希望您的绘图具有您应该设置的点和线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,
)
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句