绘制的3d表面图的x和y轴值不正确 [英] Plotly 3d surface graph has incorrect x and y axis values

查看:80
本文介绍了绘制的3d表面图的x和y轴值不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用plotly绘制3d表面图.这进行得很好,但是x和y轴上的值没有意义.它们比应有的要高得多.我为绘图使用了一个矩阵,x和y值分别是行名和列名,而z值(称为高程)当然是矩阵本身. Plotly似乎没有使用x和y数据的值.矩阵中的x和y值范围从0到6.这是我的矩阵的一小部分样本:

I would like to make a 3d surface plot with plotly. This is going quite well, however the values on the x and y axis make no sense. They are much higher than they should be. I used a matrix for the plot, the x and y values are the row and column names and the z value (called elevation) of course the matrix itself. Plotly doesn't seem to use the values of the x and y data. The x and y values range from 0 to 6 in the matrix. This is a small sample of my matrix:

head(m.dune)    
>       1.90 1.95 2    2.05 2.01 2.15 
> 0     NA   NA   NA   NA   NA   NA
> 0.05  NA   NA   NA   NA   NA   NA
> 0.10  1.14 1.14 NA   NA   NA   NA
> 0.15  1.15 1.15 1.15 1.15 1.16 1.16
> 0.20  1.16 1.16 1.16 1.16 1.16 1.17
> 0.25  1.17 1.17 1.17 1.17 1.18 1.18

这是我一直在使用的代码:

This is the code I have been using:

dune.plot <- plot_ly(z = m.dune, type = "surface") %>%
layout(
  scene=list(
    xaxis=list(title='x (m)'),
    yaxis=list(title='y (m)'),
    zaxis=list(title='Elevation (m)')))
dune.plot

该图看起来像这样,x和y轴不正确,我不确定如何获取正确的值.

The graph looks like this, with incorrect x and y axis, I am not sure how I can get correct values.

推荐答案

正如Jimbou在他的评论中指出的那样,x和y轴上的值是矩阵的行数和列数.由于我的像元大小为0.05,因此这些值不能代表正确的距离.要显示正确的距离,您必须添加正确的x和y值作为绘图图中的列表.这些x和y值必须具有相同的大小,否则部分图形将被截断.获取正确的x和y值的代码如下:

As Jimbou pointed out in his comment the values on the x and y axes are the number of rows and columns of your matrix. Since I have a cell size of 0.05, the values do not represent the correct distance. To show the correct distance you have to add the correct x and y values as list in the plotly graph. These x and y values have to have the same size, otherwise a part of the graphs gets cutoff. The code to get the correct x and y values is below:

y <- x <- as.numeric(rownames(m.dune))
# More rows than column, and the x and y should have the same size

dune1.plot <- plot_ly(z = m.dune1, x= x, y=y, type = "surface") %>%
layout(
  scene=list(
    xaxis=list(title='x (m)'),
    yaxis=list(title='y (m)'),
    zaxis=list(title='Elevation (m)')))
dune1.plot

这篇关于绘制的3d表面图的x和y轴值不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆