我正在尝试使用 plotly js 绘制 3D 散点图。有什么方法可以为小部件添加色阶,如下面的屏幕截图所示
当我尝试创建时,我只能用一些颜色渲染 3D 图表。我无法实现所附屏幕截图中的色阶和图例
https://codepen.io/rudi8292/pen/RRxBrQ
<head>
<!-- Plotly.js -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
</head>
<body>
<!-- Plotly chart will be drawn inside this DIV -->
<div id="myDiv" style="width:100%;height:100%"></div>
<button type="button" class="button" id="this_button">Click here for update</button>
<script>
/* JAVASCRIPT CODE GOES HERE */
</script>
</body>
var trace1 = {
x : [3],
y: [4],
z : [6],
mode: 'markers',
marker: {
size: 12,
line: {
color: 'rgba(217, 217, 217, 0.14)',
width: 0.5
},
opacity: 0.8
},
type: 'scatter3d'
};
var trace5 = {
x : [2],
y: [5],
z : [6],
mode: 'markers',
marker: {
size: 11,
line: {
color: 'rgba(217, 217, 217, 0.14)',
width: 0.5
},
opacity: 0.8
},
type: 'scatter3d'
};
var trace4 = {
x : [1],
y: [3],
z : [4],
mode: 'markers',
marker: {
size: 8,
line: {
color: 'rgba(217, 217, 217, 0.14)',
width: 0.5
},
mode : 'markers',
opacity: 0.8
},
type: 'scatter3d'
};
var trace2 = {
x : [2],
y: [2],
z : [2],
mode: 'markers',
marker: {
size: 15,
line: {
color: 'rgba(217, 217, 217, 0.14)',
width: 0.5
},
opacity: 0.8
},
type: 'scatter3d'
};
var trace3 = {
x : [1],
y: [1],
z : [1],
mode: 'markers',
marker: {
size: 12,
line: {
color: 'rgba(217, 217, 217, 0.14)',
width: 0.5
},
opacity: 0.8
},
type: 'scatter3d'
};
var data = [trace1, trace2,trace3,trace4,trace5];
var layout = {
margin: {
l: 0,
r: 0,
b: 0,
t: 0
},
xaxis : {
title : "This",
},
yaxis : {
title : "That"
},
zaxis : {
title : "where"
}};
Plotly.newPlot('myDiv', data, layout);
$("#this_button").click(function(){
console.log("clicked");
var update = {
x : [[1,2,3,4,5]],
y : [[1,2,3,4,5]],
z : [[1,2,3,4,5]],
size :[[12,13,14,15,16]],
'marker.color' : [["#001","#005","#0f0","#f00","#00f"]],
text : "size"
}
Plotly.restyle('myDiv', update,[0,1,2,3,4]);
});