Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing legend for mesh3d unless surface is added #2356

Open
asadow opened this issue May 29, 2024 · 0 comments
Open

Missing legend for mesh3d unless surface is added #2356

asadow opened this issue May 29, 2024 · 0 comments

Comments

@asadow
Copy link

asadow commented May 29, 2024

plotly.js added support for more trace legends but, for mesh3d, there is no legend below unless showlegend = TRUE for the mesh and a surface is added.

GH issue for more trace legends
merge for above

library(plotly)
library(rmarchingcubes)

R <- 2
f1 <- function(x, y, z){
  x^2 + y^2 + z^2 - R^2
}
f2 <- function(x, y, z){
  (x-2)^2 + (y-2)^2 + (z-2)^2 - R^2
}
g <- function(x, y, z) {
  pmax(f1(x, y, z), f2(x, y, z))
}

n <- 100
x_ <- y_ <- z_ <- seq(-R, R, length.out = n) 
Grid <- expand.grid(X = x_, Y = y_, Z = z_)
voxel <- with(Grid, array(g(X, Y, Z), dim = c(n, n, n)))
surf <- contour3d(voxel, level = 0, x_, y_, z_)
vertices <- surf$vertices
indices  <- surf$triangles - 1L

plot_ly(
  x = vertices[, 1], y = vertices[, 2], z = vertices[, 3],
  i = indices[, 1], j = indices[, 2], k = indices[, 3],
  type = "mesh3d",
  name = "hello world",
  showlegend = TRUE
) %>% layout(scene = list(aspectmode = "data"))

image

z <- c(
  c(8.83,8.89,8.81,8.87,8.9,8.87),
  c(8.89,8.94,8.85,8.94,8.96,8.92),
  c(8.84,8.9,8.82,8.92,8.93,8.91),
  c(8.79,8.85,8.79,8.9,8.94,8.92),
  c(8.79,8.88,8.81,8.9,8.95,8.92),
  c(8.8,8.82,8.78,8.91,8.94,8.92),
  c(8.75,8.78,8.77,8.91,8.95,8.92),
  c(8.8,8.8,8.77,8.91,8.95,8.94),
  c(8.74,8.81,8.76,8.93,8.98,8.99),
  c(8.89,8.99,8.92,9.1,9.13,9.11),
  c(8.97,8.97,8.91,9.09,9.11,9.11),
  c(9.04,9.08,9.05,9.25,9.28,9.27),
  c(9,9.01,9,9.2,9.23,9.2),
  c(8.99,8.99,8.98,9.18,9.2,9.19),
  c(8.93,8.97,8.97,9.18,9.2,9.18)
)
dim(z) <- c(15,6)

plot_ly(
  x = vertices[, 1], y = vertices[, 2], z = vertices[, 3],
  i = indices[, 1], j = indices[, 2], k = indices[, 3],
  type = "mesh3d",
  name = "hello",
  showscale = FALSE,
  showlegend = TRUE
) %>% 
  plotly::layout(scene = list(aspectmode = "data")) %>% 
  add_surface(z = ~z, name = "placeholder")

image

@asadow asadow changed the title Missing legend for traces Missing legend for mesh3d unless surface is added May 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant