【问题标题】:fix position colorbar for multiple plot plotly修复多个绘图的位置颜色条
【发布时间】:2017-10-25 18:45:10
【问题描述】:
x1 = c(1:10)
y1 = c(1:10)
z1 = matrix(runif(100,0,25),ncol = 10)
z1_col = matrix(runif(100,0,25),ncol = 10)

x2 = c(2:11)
y2 = c(2:11)
z2 = matrix(runif(100,0,100),ncol = 10)
z2_col = matrix(runif(100,0,25),ncol = 10)

x3 = c(3:12)
y3 = c(3:12)
z3 = matrix(runif(100,0,10),ncol = 10)
z3_col = matrix(runif(100,0,25),ncol = 10)

x4 = c(3:12)
y4 = c(3:12)
z4 = matrix(runif(100,0,5),ncol = 10)
z4_col = matrix(runif(100,0,25),ncol = 10)

我正在尝试固定颜色条的位置。我已经尝试通过为每个绘图添加颜色条的 x 和 y 轴来修复它。

plot_ly(type = "surface", colors = c("blue","green","yellow","orange","red")) %>%
  add_trace(x = ~ x1, y = ~ y1, z = ~ z1, surfacecolor = ~ z1_col,
            colorbar = list(title = "Concentration", x = 1, y = 0.5)) %>%
  add_trace(x = ~ x2, y = ~ y2, z = ~ z2, surfacecolor = ~ z2_col,visible = F,
            colorbar = list(title = "Concentration", x = 1, y = 0.5)) %>%
  add_trace(x = ~ x3, y = ~ y3, z = ~ z3, surfacecolor = ~ z3_col,visible = F,
            colorbar = list(title = "Concentration", x = 1, y = 0.5)) %>%
  add_trace(x = ~ x4, y = ~ y4, z = ~ z4, surfacecolor = ~ z4_col,visible = F,
            colorbar = list(title = "Concentration", x = 1, y = 0.5)) %>%
  layout(updatemenus = list(
    list(
      y = 0.8,
      # FOR line, point, to show A, list(T,F,F)
      # but for 3D, list (F,T,F)
      buttons = list(
        list(method = "restyle",
             args = list("visible",list(F,T,F,F)),
             label = "A"),
        list(method = "restyle",
             args = list("visible",list(F,F,T,F)),
             label = "B"),
        list(method = "restyle",
             args = list("visible",list(F,F,F,T)),
             label = "C"),
        list(method = "restyle",
             args = list("visible",list(T,F,F,F)),
             label = "D")
      )
    )
  ))

但是,每当我更改为新绘图时,颜色条的位置都会更改(向下移动)。 有什么办法可以固定所有情节的颜色条的位置吗?

【问题讨论】:

    标签: r plotly colorbar


    【解决方案1】:

    尝试将 colorbar 参数移到 add_trace() 之外,而不是

    plot_ly(type = "surface", colors = c("blue","green","yellow","orange","red")) %>%
      add_trace(x = ~ x1, y = ~ y1, z = ~ z1, surfacecolor = ~ z1_col,
      colorbar = list(title = "Concentration", x = 1, y = 0.5)) ...
    

    做:

    plot_ly(type = "surface", colors = c("blue","green","yellow","orange","red")) %>%
      add_trace(x = ~ x1, y = ~ y1, z = ~ z1, surfacecolor = ~ z1_col) %>% 
      colorbar(title = "Concentration", x = 1, y = 0.5) %>% ...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      • 2016-07-20
      • 2015-04-16
      • 2021-01-17
      相关资源
      最近更新 更多