如何在 Plotly.js 散点图中将所有 y 轴平移在一起?

How can I pan all y axes together in my Plotly.js scatter plot?

提问人:gib65 提问时间:10/11/2023 更新时间:10/11/2023 访问量:26

问:

我有一个具有多个序列的 Plotly.js 散点图。我想沿 y 轴平移,并一起查看所有系列平移。目前,它们不会一起平移。取而代之的是,只有一个系列平移,另一个不动。

平移前:

enter image description here

平移后:

enter image description here

我需要两个系列都位于单独的 y 轴上,因为它们具有不同的单位并且它们的比例相差几个数量级,但这并不意味着它们不能一起平移。

以下是系列数据:

[
   {
      "type":"scatter",
      "x":[...],
      "y":[...],
      "hovertemplate":"%{x}<br>%{y:.2f} %{text}<extra></extra>",
      "text":[...],
      "name":"°C",
      "marker":{
         "color":"#89d300",
         "size":1,
         "opacity":1
      },
      "line":{
         "width":1
      },
      "yaxis":"y",
      "connectgaps":true,
      "measurementGroupId":18
   },
   {
      "type":"scatter",
      "x":[...],
      "y":[...],
      "hovertemplate":"%{x}<br>%{y:.2f} %{text}<extra></extra>",
      "text":[...],
      "name":"kWh",
      "marker":{
         "color":"#2fb5ea",
         "size":1,
         "opacity":1
      },
      "line":{
         "width":1
      },
      "yaxis":"y2",
      "connectgaps":true,
      "measurementGroupId":2
   }
]

这是布局:

{
   "title":{
      "text":"Time Series",
      "font":{
         "color":"#3dcd58",
         "family":"Nunito-Regular",
         "size":18
      },
      "xanchor":"left",
      "x":0
   },
   "font":{
      "color":"#333",
      "family":"Nunito-Regular"
   },
   "dragmode":"select",
   "autosize":false,
   "width":425,
   "height":400,
   "margin":{
      "l":20,
      "r":15,
      "b":30,
      "t":30
   },
   "plot_bgcolor":"#ffffff",
   "showlegend":true,
   "legend":{
      "x":0,
      "bgcolor":"rgba(255,255,255,0.3)"
   },
   "xaxis":{
      "range":[
         1663809180000,
         1698403740000
      ]
   },
   "hovermode":"closest",
   "yaxis":{
      "showticklabels":false,
      "range":[
         2.133101851851852,
         31.59375
      ]
   },
   "yaxis2":{
      "showticklabels":false,
      "overlaying":"y",
      "range":[
         -948.1500000000001,
         41163.15
      ]
   }
}
散点图 plotly.js yaxis pan

评论


答: 暂无答案