【问题标题】: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?

谢谢

【问题讨论】:

  • 你能发布你的代码吗?
  • 你在 Plotly 中看到了什么?

标签: 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/ 示例:

    在跟踪对象中,您可以为textname 提供'&lt;text&gt;&lt;{}&gt;'.format(&lt;value(s)&gt;)。在&lt;text&gt; 中,如果您也想要的话,您也可以插入\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... 
                       ) 
    

    希望这会有所帮助

    【讨论】:

      猜你喜欢
      • 2016-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-02
      • 2020-07-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多