简体   繁体   English

plotly 散点数据中的色标 plot

[英]plotly colorscale in scatter data plot

Using marker:{color:x} in javascript plotly ( http://jsfiddle.net/d8bt1qof/ ), I can color-code my data:在 javascript plotly 中使用marker:{color:x}http://jsfiddle.net/d8bt1qof/ ),我可以对我的数据进行颜色编码:

But how can I change the colorscale?但是我怎样才能改变色阶呢?

Different colorscales seems to be available ( https://plotly.com/javascript/colorscales/ ), but the usage is only explained for heatmap plots.似乎可以使用不同的色标( https://plotly.com/javascript/colorscales/ ),但仅对热图图的用法进行了说明。 And adding colorscale: 'Portland' seems not to work.并添加colorscale: 'Portland'似乎不起作用。

scattergl trace markers can also have a colorschale . colorschale跟踪标记也可以有一个颜色表。 I found a reference for it in the documentation here :我在这里的文档中找到了它的参考:

colorscale Parent: data[type=scattergl].marker Type: colorscale Sets the colorscale. colorscale 父级:data[type=scattergl].marker 类型:colorscale 设置色阶。 Has an effect only if in marker.color is set to a numerical array.仅当在marker.color中设置为数值数组时才有效。 The colorscale must be an array containing arrays mapping a normalized value to an rgb, rgba, hex, hsl, hsv, or named color string.色标必须是包含 arrays 的数组,将标准化值映射到 rgb、rgba、hex、hsl、hsv 或命名颜色字符串。 At minimum, a mapping for the lowest (0) and highest (1) values are required.至少,需要最低 (0) 和最高 (1) 值的映射。 For example, [[0, 'rgb(0,0,255)'], [1, 'rgb(255,0,0)']] .例如, [[0, 'rgb(0,0,255)'], [1, 'rgb(255,0,0)']] To control the bounds of the colorscale in color space, use marker.cmin and marker.cmax .要控制颜色空间中的色标范围,请使用marker.cminmarker.cmax Alternatively, colorscale may be a palette name string of the following list: Greys,YlGnBu,Greens,YlOrRd,Bluered,RdBu,Reds,Blues,Picnic,Rainbow,Portland,Jet,Hot,Blackbody,Earth,Electric,Viridis,Cividis.或者, colorscale可以是以下列表的调色板名称字符串:Greys,YlGnBu,Greens,YlOrRd,Bluered,RdBu,Reds,Blues,Picnic,Rainbow,Portland,Jet,Hot,Blackbody,Earth,Electric,Viridis,Cividis。

So an example based on your fiddle you could look like this:因此,基于您的小提琴的示例可能如下所示:

var x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

var trace1 = {
  x: x,
  y: x,
  mode: 'markers',
   marker: {
    size: 20,
    color: x,
    colorscale: 'Greens'
  },
};

Plotly.newPlot('myDiv', [trace1], {});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM