Black Lives Matter. Please consider donating to Black Girls Code today.
Learn how to use COVID-19 data in open source Dash apps. Register for the Sept 23rd webinar with IQT!

3D surface plot Absolute Color Bar

Hello,

I am using plotly through the R API and Shiny.
I have a surface plot with z values between 0 and 1.5.
I would like to fix the color-value mapping for my plot so that the colors scale represents z values from 0 to 1.5. So in this case the top and bottom number labels on the color bar would be 0 and 1.5 respectively and any data in the plot would map to the same color regardless of the range of the data. Right now the color bar is relative meaning there is a fixed range of colors and the min and max z values map to each end of the color bar. This does not make the comparison of surface charts easy. Here is the basic code I am using to generate it.

p <- plot_ly(x = xVal,y = Yval,z = Zval, type = "surface")

I haven’t been able to do this even in the plotly web GUI environment.
Thanks.

Use zmin and zmax

1 Like

When I tried this I initially thought my problem was solved. Unfortunately this only fixed the labeling of the color bar. It did not fix the color-value mapping. So if my data is between 0 and 0.5 the color of the highest data will still match the top of the color bar even though the top of the color bar is labeled 1.5. Is there is was to fix this?

You might need to upgrade your plotly package in order to see the change. An issue with zmin and zmax was fixed only recently https://github.com/plotly/plotly.js/releases/tag/v1.4.0

It was pretty recently installed, version 2.0.16.

would you mind sharing a reproducible example?

plot_ly(z = volcano, type = "surface", zmin=0,zmax=300)

The top of the volcano at 195 is yellow but the yellow on the color bar does not start until 250

1 Like

Thanks for the example. We’ve recently addressed this issue but the update is not yet reflected in our CRAN release. For now, you could use our latest development version:

# install.packages("devtools") devtools::install_github("ropensci/plotly")

and I will update this thread when we update our CRAN release.

1 Like