colorscale =“彩虹";在plot_ly中不起作用 [英] colorscale = "Rainbow" in plot_ly doesn't work

查看:131
本文介绍了colorscale =“彩虹";在plot_ly中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用plot_ly软件包绘制3d曲面.

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 ?

推荐答案

文档:

色标(colorscale)
设置色阶.色阶必须为 包含将规范化值映射到rgb,rgba, 十六进制,hsl,hsv或命名的颜色字符串.至少, 需要最低(0)和最高(1)值. 例如,[[0, 'rgb(0,0,255)', [1, 'rgb(255,0,0)']].

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)']].

您可以使用

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

这给你

这篇关于colorscale =“彩虹";在plot_ly中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆