【问题标题】:Comparing datasets with plotly - mix dashed with solid lines将数据集与 plotly 进行比较 - 用实线混合虚线
【发布时间】:2019-07-20 14:01:04
【问题描述】:

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

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

从某种意义上说,我正在尝试比较两个具有相同确切列名但它们需要具有不同的行格式以便于比较的数据帧。

附: help(go.Layout) 仅包含有关spikedlines 的信息,但没有关于通常的行格式的信息。

非常感谢,

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)

【问题讨论】:

    标签: python pandas plot jupyter-notebook plotly


    【解决方案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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-01
      • 1970-01-01
      • 2018-06-22
      • 2012-09-12
      • 2021-06-12
      • 1970-01-01
      • 2014-05-17
      • 1970-01-01
      相关资源
      最近更新 更多