如何通过plotly的go.Layout为数据框数据集指定虚线还是虚线?以下是我的代码,该代码使用数据框并以实线吐出绘图。
我想使用第二个数据框对象在同一图中绘制虚线。
从某种意义上说,我正在尝试比较两个具有相同确切列名的数据框,但是它们需要具有不同的行格式以便于比较。
P.S。 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)
答案 0 :(得分:1)
找出解决方案并回答可能会解决此类错误的其他问题。
添加操作必须在数据对象本身中完成。
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)