Multiple Y-axis on graph not aligned

蹲街弑〆低调 提交于 2019-12-11 12:13:33

问题


I created a graph through R's Plotly library. The graph has 2 y-axis's and everything looks fine, except that the y-axis's are misaligned. How do I "realign" it?


回答1:


Python answer here

Had the same issue, add rangemode = "tozero" to your overlaying axis

plot_ly(data = dat,
      x = x,
      y = y,
      type = "bar",
      name = "Y") %>%
add_trace(data = par,
          x = x,
          y = Z,
          name = "Z",
          yaxis = "y2") %>%
layout(yaxis2 = list(overlaying = "y",
                     side = "right",
                     rangemode = "tozero"))



回答2:


In the layout function, you can set axis ranges manually. You can use this to align them. Often, the scale of your two traces will be very different, though.

plot_ly(...) %>%
add_trace(..., yaxis = "y2") %>%
layout(
  yaxis = list(
    range = c(-2, 2)
  ),
  yaxis2 = list(
    range = c(-2, 2)
  )
)


来源:https://stackoverflow.com/questions/35880139/multiple-y-axis-on-graph-not-aligned

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!