javascript - 如何在 plotly 中为每个跟踪添加标签?
问题描述
正如您在上图中看到的,我有两条热图类型的轨迹,我想在每条轨迹下方添加轨迹名称。
以下是codepen链接:Codepen
添加代码:
索引.html
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<h1>Heatmap</h1>
<div id="maincontainer">
<div id="r1c2-content"></div>
</div>
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="charts.js"></script>
</body>
</html>
图表.js
let ra = (num)=>{
data = []
vals = [0, 0.5, 1]
for(let i = 0; i < num; i++){
data.push(vals[parseInt(Math.random()*vals.length)])
}
return data
}
let plot_heatmap = () => {
// heatmap
var hmdata = [
{
x0: 0.5,
y0: 0.5,
z: [[0,1], [1,0.5], [0.5,0]],
type: 'heatmap',
showscale: false,
showlegend: false,
colorscale: [
[0, 'green'],
[0.5, 'red'],
[1, 'yellow']
],
},
{
x0: 3.5,
y0: 0.5,
z: [[1, 0.5, 0.5], [0, 0.5, 0.5], [0, 1, 0.5]],
type: 'heatmap',
showscale: false,
colorscale: [
[0, 'green'],
[0.5, 'red'],
[1, 'yellow']
],
autocolorscale: false
},
];
var layout = {
height: 400,
width: 500
}
Plotly.newPlot('r1c2-content', hmdata, layout);
}
plot_heatmap()
解决方案
推荐阅读
- python - 用 NaN 替换 None 并忽略 Pandas 中的 NoneType
- c - 为什么我的小 C 循环不能正确打印到帧缓冲区,但它的展开版本却可以?
- python - 在数据帧切片上并行化 Pandas 的正确方法
- javascript - Material-ui jss 不尊重 justify 内容
- android - Android视图旋转Y不适用于带有Nougat的华为
- sql-server - 在 SQL Server 2014 中安排其他成功的作业
- algorithm - 3种不同情况下插入堆的时间复杂度
- javascript - 如何将实例化的 File 对象与 JavaScript 中的输入链接?
- c# - 鼠标悬停时保持工具提示打开
- python - 生成器在 locateOnScreen 时引发 StopIteration