你可以删除Plotly Python Scatter3d中的悬停坐标线

时间:2017-09-21 16:10:41

标签: python-3.x plotly scatter3d

使用Plotly Scatter3D时,默认的鼠标悬停效果会显示一种坐标十字准线。有没有办法删除此效果,只显示工具提示?

1 个答案:

答案 0 :(得分:3)

导致线条显示在轴上的悬停效果在Plotly中称为spikes。您可以通过layout = {'scene': {'xaxis': {'showspikes': False}}}停用它们。

交互式Javascript示例:

Plotly.d3.csv('https://raw.githubusercontent.com/plotly/datasets/master/3d-scatter.csv', function(err, rows) {
  function unpack(rows, key) {
    return rows.map(function(row) {
      return row[key];
    });
  }
  var trace = {
    x: unpack(rows, 'x2'),
    y: unpack(rows, 'y2'),
    z: unpack(rows, 'z2'),
    mode: 'markers',
    marker: {
      color: 'rgb(127, 127, 127)',
      size: 12,
      symbol: 'circle',
      line: {
        color: 'rgb(204, 204, 204)',
        width: 1
      },
      opacity: 0.9
    },
    type: 'scatter3d'
  };
  var data = [trace];
  var layout = {
    scene: {
      xaxis: {
        showspikes: false
      },
      yaxis: {
        showspikes: false
      },
      zaxis: {
        showspikes: false
      }
    }
  };
  Plotly.newPlot('myDiv', data, layout);
});
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
<div id="myDiv" style="width:100%;height:100%"></div>