【问题标题】:Dash/Plotly: How can I plot two columns on the y-axis with the same x axis?Dash/Plotly:如何在 y 轴上绘制具有相同 x 轴的两列?
【发布时间】:2021-06-30 14:46:25
【问题描述】:

我正在尝试在同一个折线图上绘制我的数据集中的两列(这些列是“病例”和“疫苗接种”)。 x 轴只有一列(即“国家”)我希望他们共享。是否可以在 Dash/Plotly 中执行此操作?我找不到使用 Dash 的任何解决方案。这是我的代码的 sn-p:

                 html.Div(
                    children=dcc.Graph(
                        id="cases-chart",
                        config={"displayModeBar": False},
                        figure={
                            "data": [
                                {
                                    "x": data["country"],
                                    "y": data["cases"],
                                    "type": "lines",
                                },
                            ],
                            "layout": {
                                "title": {
                                    "text": "Cases by Country",
                                    "x": 0.05,
                                    "xanchor": "left",
                                },
                                "xaxis": {"fixedrange": True},
                                "yaxis": {"fixedrange": True},
                                "colorway": ["#17B897"],
                            },
                        },
                    ),
                    className="card",
                ),

谢谢。

【问题讨论】:

    标签: python plotly-dash yaxis


    【解决方案1】:

    尝试将另一个元素添加到包含所需数据的“数据”列表中。

    您可以在the documentation找到更多信息

    【讨论】:

      【解决方案2】:

      找到解决办法:

      "data": [
                                      {
                                          "x": data["country"],
                                          "y": data["vaccinations"],
                                          "type": "lines",
                                      },
                                      {
                                          "x": data["country"],
                                          "y": data["cases"],
                                          "type": "lines",
                                      }
                                  ],
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2021-11-13
        • 2022-07-06
        • 1970-01-01
        • 1970-01-01
        • 2016-08-25
        • 2019-04-08
        • 1970-01-01
        相关资源
        最近更新 更多