我希望有两个并排的图形共享相同的X轴和同一个工具栏。这意味着,通过放大第一个图,第二个图应该自动调整大小到相同的缩放区域。
这样做的一种方法是使用shareX=TRUE将图幅放在另一个之上,但我需要它们并排。
在python中,似乎有一种方法可以使用fig.update_xaxes(matches='x')来实现。R也有类似的选择吗?
下面是一个示例代码:
library(plotly)
n = 10
x = 1:n
y = rnorm(n)
fig1 <- plot_ly(x = x, y = y, type = 'scatter', mode = 'lines+markers')
fig2 <- plot_ly(x = x, y = y, type = 'scatter', mode = 'lines+markers')
fig <- subplot(fig1, fig2, shareX = TRUE) # shareX actually not working here
fig提前谢谢你!
发布于 2022-01-25 08:54:14
我们可以在R中使用matches,就像在python中一样。
运行schema()并导航:
对象layoutAttributes►布局►►xaxis►匹配
了解更多信息。
这使所有(x&y)轴同步:
library(plotly)
n = 10
x = 1:n
y = rnorm(n)
fig1 <- plot_ly(x = x, y = y, type = 'scatter', mode = 'lines+markers')
fig2 <- plot_ly(x = x, y = y, type = 'scatter', mode = 'lines+markers', xaxis = "x") %>% layout(xaxis = list(matches = "x"))
fig <- subplot(fig1, fig2, shareX = TRUE, shareY = TRUE)
fig

https://stackoverflow.com/questions/70837051
复制相似问题