我们如何通过平地的go.Layout为数据集指定虚线和虚线?下面是我的代码,它使用了一个dataframe,并用实线显示了一个图。
我想使用第二个dataframe对象在相同的情节中有虚线。
在某种意义上,我试图比较两个数据格式,它们具有相同的确切列名,但它们需要有不同的行格式,以便更容易地进行比较。
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)发布于 2019-02-26 23:40:06
找出解决办法,并为其他可能会遇到此类错误的人提供答案。
需要在数据对象本身中进行添加。
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)https://stackoverflow.com/questions/54895462
复制相似问题