gpt4 book ai didi

python - 将数据集与绘图进行比较 - 将虚线与实线混合

转载 作者:行者123 更新时间:2023-12-01 08:17:35 29 4
gpt4 key购买 nike

我们如何通过plotly的go.Layout为dataframe数据集指定虚线和虚线?下面是我的代码,它使用数据框并用实线绘制出一个图。

我想使用第二个数据框对象在同一图中显示虚线。

从某种意义上说,我试图比较两个具有完全相同的列名称的数据框,但它们需要具有不同的行格式以便于比较。

附注help(go.Layout) 仅包含有关尖刺线的信息,但不包含通常线格式的信息。

非常感谢,

init_notebook_mode(connected=True)
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd

#sample dataframe defined into `df1`

plot_df = [{
'x': df1.index,
'y': df1[col],
'name': col
} for col in df1.columns]

layout= go.Layout(
title= 'Plot_with_solidline',
xaxis= dict(title= 'Iteration'),
yaxis=dict(title= 'Accuracy'),
showlegend= True
)
fig= go.Figure(data=plot_df, layout=layout)
plot(fig, filename='pandas-line-naming-traces', auto_open=False)

最佳答案

找出解决方案并回答其他可能遇到此类错误的人。

添加需要在数据对象本身中完成。

init_notebook_mode(connected=True)
import plotly.plotly as py
import plotly.graph_objs as go
import pandas as pd

#sample dataframe defined into `df1`, `df2`

layout=go.Layout(
title= 'Plot_with_solidline_dashline',
xaxis= dict(title= 'Iteration'),
yaxis=dict(title= 'Accuracy'),
showlegend= True
)
plot_df=[]
for col in df1.columns:
plot_df.append(
go.Scatter(x=df1.index, y=df1[col], mode='lines', line={'dash': 'solid'}, name=col)
)
plot_df.append(
go.Scatter(x=df2.index, y=df2[col], mode='lines', line={'dash': 'dash'}, name=col)
)

fig= go.Figure(data=plot_df, layout=layout)
plot(fig, filename='pandas-line-naming-traces', auto_open=False)

关于python - 将数据集与绘图进行比较 - 将虚线与实线混合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54895462/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com