【问题标题】:plotly - changing the line stylesplotly - 改变线条样式
【发布时间】:2016-09-14 20:31:34
【问题描述】:

我正在尝试在绘图图上绘制多个但相关的事物。

我想同时区分和关联这些线条。为了让自己更清楚,我正在绘制我训练的分类器的 ROC 特征。我想要一个颜色相同但线型不同的特定分类器用于训练方法。

我目前使用它来满足我的要求:

这是相同的代码,

    data = [
        go.Scatter(
            mode='lines+markers',
            x=df_LogisticRegression['FPR'], # assign x as the dataframe column 'x'
            y=df_LogisticRegression['TPR'],
            name = "Logistic Regression all attributes",
            marker=dict(
                color="blue",
                symbol='square'
            ),
        ),
        # and so on for all other algos
        go.Scatter(
            mode='lines+markers',
            x=df_LogisticRegression_nonSP['FPR'], # assign x as the dataframe column 'x'
            y=df_LogisticRegression_nonSP['TPR'],
            name = "Logistic Regression non-sparse attributes",
            marker=dict(
                color="blue",
                symbol='square-open'
            ),
        ),
         # and so on for all other algos
    ]
layout = go.Layout(
    title='ROC Curve',
    yaxis=dict(title='True Positive Rates(TPR)'),
    xaxis=dict(title='False Positive Rates(FPR)')
)
fig = go.Figure(data=data,layout=layout)
iplot(fig)

例如, 我希望逻辑回归的颜色为蓝色,但“所有属性应为实线”的颜色应为实线,“非稀疏属性”的颜色应为虚线。

我试图查找并阅读 plotly 的文档,但找不到任何帮助。

【问题讨论】:

  • 当您在模式下编写lines 时,即使点稀疏,它也会绘制线条。它将加入点。
  • 对非稀疏数据集试试mode=markers
  • 我需要一条线,我不能以任何方式改变线型吗?我正在查看Plotly shapes 和其中的第一个示例,是否有类似的事情可以实现?
  • 是的,要画一条线,只需说mode=lines
  • 我在Plotly line graphs 上找到了解决方案。谢谢你。对我来说是一个尤里卡时刻! :)

标签: python plot plotly roc


【解决方案1】:

这是因为 plotly 根据您要求它执行的模式绘制数据。如果您说mode=markers,它将仅绘制标记。如果您说mode=lines,它将连接数据中的所有点并将其绘制为线。

请参阅此页面https://plot.ly/python/line-and-scatter/#line-and-scatter-plots 以获取更多可以使用 plotly 绘制的线条示例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-01-17
    • 1970-01-01
    • 2018-09-04
    • 2021-10-31
    • 1970-01-01
    • 2012-04-05
    • 2020-12-29
    相关资源
    最近更新 更多