gpt4 book ai didi

javascript - 更改plotly js中的z索引标签

转载 作者:行者123 更新时间:2023-12-02 22:34:33 24 4
gpt4 key购买 nike

我想更改plotlyjs中的z-index标签我正在使用以下代码。目前,它在悬停时显示 X、Y、Z。 X、Y值良好。我想知道是否有什么方法可以改变Z的值标签?将鼠标悬停在图表上时,我希望 Z 显示为“值”。如何得到它?

var data = [ {
z: [[10, 10.625, 12.5, 15.625, 20],
[5.625, 6.25, 8.125, 11.25, 15.625],
[2.5, 3.125, 5., 8.125, 12.5],
[0.625, 1.25, 3.125, 6.25, 10.625],
[0, 0.625, 2.5, 5.625, 10]],
type: 'contour',
colorscale: [[0, 'rgb(166,206,227)'], [0.25, 'rgb(31,120,180)'], [0.45, 'rgb(178,223,138)'], [0.65, 'rgb(51,160,44)'], [0.85, 'rgb(251,154,153)'], [1, 'rgb(227,26,28)']]
}
];

var layout = {
title: 'Custom Contour Plot Colorscale'
};

Plotly.newPlot('myDiv', data, layout);

最佳答案

尝试使用hovertemplate选项(https://plot.ly/javascript/reference/#contour-hovertemplate):

var data = [ {
z: [[10, 10.625, 12.5, 15.625, 20],
[5.625, 6.25, 8.125, 11.25, 15.625],
[2.5, 3.125, 5., 8.125, 12.5],
[0.625, 1.25, 3.125, 6.25, 10.625],
[0, 0.625, 2.5, 5.625, 10]],
type: 'contour',
colorscale: [[0, 'rgb(166,206,227)'], [0.25, 'rgb(31,120,180)'], [0.45, 'rgb(178,223,138)'], [0.65, 'rgb(51,160,44)'], [0.85, 'rgb(251,154,153)'], [1, 'rgb(227,26,28)']],
hovertemplate: 'x: %{x}, y: %{y}, Value: %{z}<extra></extra>'
}
];

var layout = {
title: 'Custom Contour Plot Colorscale'
};

Plotly.newPlot('myDiv', data, layout);
<script src="https://cdnjs.cloudflare.com/ajax/libs/plotly.js/1.49.5/plotly.min.js"></script>
<div id=myDiv>

</div>

关于javascript - 更改plotly js中的z索引标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58780648/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com