【问题标题】:Is it possible to manually set the scale and ticks on a plot.ly 3D scatter graph?是否可以在 plot.ly 3D 散点图上手动设置比例和刻度?
【发布时间】:2016-06-07 21:00:00
【问题描述】:

我有一个基本的 plot.ly 3D 散点图,其中包含在三个维度中指定的各种路径。经过三天的阅读文档,我仍然没有找到一种方法来定义我的轴的刻度间隔。它似乎是根据我的数据自动生成它们,这是我不想要的。实际上,我需要我的三个轴的比例为 1:1:1,这可能吗?

<style>html, body { height: 100%; }</style>
<div id="myDiv" style="width: 100%; height: 100%"></div>

<!-- Latest compiled and minified plotly.js JavaScript -->
<script type="text/javascript" src="https://cdn.plot.ly/plotly-latest.min.js"></script>

<script>
var data = [
  {
    x: [-886, -719],
    y: [-4785, -5192],
    z: [527, 501],
    type: 'scatter3d'
  },
  {
    x: [-1782, -92],
    y: [1740, -5172],
    z: [18, 252],
    type: 'scatter3d'
  },
  {
    x: [3844, -450],
    y: [35, -5185],
    z: [20, 219],
    type: 'scatter3d'
  },
  {
    x: [2770, 761],
    y: [2360, -5122],
    z: [246, 96],
    type: 'scatter3d'
  },
  {
    x: [3800, 546],
    y: [-3419, -5215],
    z: [57, 311],
    type: 'scatter3d'
  },
  {
    x: [-340, 775],
    y: [-3893, -5189],
    z: [573, 135],
    type: 'scatter3d'
  },
  {
    x: [-3141, -41],
    y: [3677, -5205],
    z: [18, 383],
    type: 'scatter3d'
  },
  {
    x: [19, -546],
    y: [261, -5181],
    z: [74, 93],
    type: 'scatter3d'
  },
  {
    x: [3, 789],
    y: [394, -5165],
    z: [112, 421],
    type: 'scatter3d'
  }
];
var layout = {
  // height: 700,
  // width: 700,
  xaxis: {
    range: [-5000, 5000]
  },
  yaxis: {
    range: [-5000, 5000]
  }
};
Plotly.newPlot('myDiv', data, layout);
</script>

代码演示:https://rocket-league-replays.github.io/3d-hitmaps/

【问题讨论】:

    标签: javascript plotly


    【解决方案1】:

    我对javascript plotly api不太熟悉,这个答案是用python写的。希望它对您的情况也有帮助。

    如果我正确理解您的问题,您想为轴设置刻度模式,并且根据您选择的模式,您还想设置任一刻度;滴答0和滴答;或滴答声。

    以下内容来自:https://plot.ly/python/reference/#layout-scene-xaxis-tickmode 一个难以有效搜索但非常有用的页面。页面的javascript版本为:https://plot.ly/javascript/reference/#layout-scene-xaxis-tickmode

    tickmode(枚举:“auto”|“linear”|“array”) 设置此轴的刻度模式。如果为“auto”,则通过nticks 设置刻度数。如果为“线性”,则刻度的位置由起始位置tick0 和刻度步长dtick 确定(如果提供了tick0dtick,则“线性”是默认值)。如果为“array”,则刻度的位置通过tickvals 设置,刻度文本为ticktext。 (如果提供了tickvals,则“array”是默认值)。

    【讨论】:

      【解决方案2】:

      这同样适用于 python,但是在场景选项中,有一种方法可以使用下面的 xaxis(或 yaxis 或 zaxis)中的 range(list) 选项来设置 x、y 或 z 轴的范围。示例代码。

       scene = dict(xaxis=dict(gridcolor='rgb(0, 0, 0)',
                                          zerolinecolor='rgb(0, 0, 0)',
                                          showbackground=False,
                                          range = (minX,maxX)),
                              yaxis=dict(gridcolor='rgb(0, 0, 0)',
                                         zerolinecolor='rgb(0, 0, 0)',
                                         showbackground=False,
                                         range = (minY, maxY)),
                              zaxis=dict(gridcolor='rgb(0, 0, 0)',
                                          zerolinecolor='rgb(0, 0, 0)',
                                          showbackground=False,
                                         range = (minZ, maxZ)))
       fig['layout'].update(scene)
      

      这里是文档:https://plot.ly/python/reference/#layout-xaxis-range 和用于 java 的 https://plot.ly/javascript/reference/#layout-xaxis-range

      【讨论】:

        【解决方案3】:

        是的,当然。可以在Plotly's documentation 中查看有关如何为 3d 图表设置轴格式的信息。

        代码方面,你想要的是这样的

        var layout = {
          scene:{
             aspectmode: "manual",
           aspectratio: {
             x: 1, y: 1, z: 1,
            },
           xaxis: {
            nticks: 100,
            range: [-5000, 5000],
          },
           yaxis: {
            nticks: 100,
            range: [-5000, 5000],
          },
           zaxis: {
           nticks: 100,
           range: [-5000, 5000],
          }},
        };
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-03-28
          • 2021-12-28
          • 2021-01-19
          • 1970-01-01
          • 2018-09-02
          • 1970-01-01
          • 2020-10-07
          相关资源
          最近更新 更多