colorscale = “Rainbow” in plot_ly doesn't work

淺唱寂寞╮ 提交于 2019-12-11 12:58:23

问题


I am trying to plot a 3d surface by using plot_ly package.

x = c(1:10)
y = c(1:10)
z = matrix(runif(100),ncol = 10)
z_col = matrix(runif(100),ncol = 10)

plot_ly(x = ~x, y = ~y, z = ~z, surfacecolor =~ z_col, 
        type = "surface", colorscale = "Rainbow")

I expect the the color for the color bar will be like this:

However, this is what I get:

Can anyone show me how to show this problem ?


回答1:


From the documentation:

colorscale (colorscale)
Sets the colorscale. The colorscale must be an array containing arrays mapping a normalized value to an rgb, rgba, hex, hsl, hsv, or named color string. At minimum, a mapping for the lowest (0) and highest (1) values are required. For example, [[0, 'rgb(0,0,255)', [1, 'rgb(255,0,0)']].

You can define your own rainbow colorscale by using

colorscale = cbind(seq(0, 1, by=1/(length(z) - 1)), rainbow(length(z)))

which gives you



来源:https://stackoverflow.com/questions/46893717/colorscale-rainbow-in-plot-ly-doesnt-work

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