【问题标题】:In Plotly is there a way to increase the number of simultaneous hover values?在 Plotly 中有没有办法增加同时悬停值的数量?
【发布时间】:2018-02-08 22:25:48
【问题描述】:
我有一个包含 6 个值的图。但是,当我悬停时,它只显示 5。我希望它显示 6 个值。我猜最大值是 5。
1)我的猜测是对的,还是别的什么?
2)如果我猜对了,有没有办法将其设置为大于5?
谢谢
【问题讨论】:
标签:
python
hover
plotly
scatter-plot
scatter
【解决方案1】:
我不相信有限制,但 Plotly 只会根据 div 的高度显示一定数量的标签。我发现增加高度会显示更多悬停值。
这是一个小提琴:https://jsfiddle.net/L4acvue2/
请注意,更改高度会更改显示的标签数量。
你可以用这样的东西来测试:
TESTER = document.getElementById('tester');
var lines = [];
for (var i = 0; i < 100; i++) {
lines.push({
x: [1, 2, 3, 4, 5],
y: [1, 2, 4, 8, 16]
});
}
Plotly.plot( TESTER, lines, {
margin: { t: 0 } } );
/* Current Plotly.js version */
console.log( Plotly.BUILD );
<head><script src="https://cdn.plot.ly/plotly-latest.min.js"></script></head>
<!-- Plots go in blank <div> elements.
You can size them in the plot layout,
or give the div a size as shown here.
-->
<div id="tester" style="width:600px;height:250px;"></div>
【解决方案2】:
参考 Plotly 的 Hover https://plot.ly/python/line-and-scatter/ 示例:
在跟踪对象中,您可以为text 和name 提供'<text><{}>'.format(<value(s)>)。在<text> 中,如果您也想要的话,您也可以插入\n 来换行。
trace0= go.Scatter(
x= data['rank'],
y= data['pop']+(i*1000000),
mode= 'markers',
marker= dict(size= 14,
line= dict(width=1),
color= c[i],
opacity= 0.3),
name= y[i],
text= data['state'] # The hover text goes here...
)
希望这会有所帮助