R:从绘图X,Y,Z三维表面 [英] R: Plotting a 3D surface from x, y, z

查看:255
本文介绍了R:从绘图X,Y,Z三维表面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想象我有一个3列矩阵
的x,y和z 其中,z是x和y的函数。

imagine I have a 3 columns matrix
x, y, z where z is a function of x and y.

我知道如何绘制散点图这些点与 PLO​​T3D(X,Y,Z)

I know how to plot a "scatter plot" of these points with plot3d(x,y,z)

但是,如果我想要一个面,而不是我必须用其他的命令,如surface3d 的问题是,它不接受相同的输入PLOT3D 它似乎需要与基质

But if I want a surface instead I must use other commands such as surface3d The problem is that it doesn't accept the same inputs as plot3d it seems to need a matrix with

(nº elements of z) = (n of elements of x) * (n of elements of x)

我怎样才能得到这个矩阵? 我试着用命令插值,因为我做的时候,我需要用等高线图。

How can I get this matrix? I've tried with the command interp, as I do when I need to use contour plots.

我怎么能直接从X,Y,Z绘制表面没有计算这个矩阵? 如果我有太多了点这个矩阵是太大了。

How can I plot a surface directly from x,y,z without calculating this matrix? If I had too many points this matrix would be too big.

欢呼声

推荐答案

如果你的x和y COORDS不在一个网格,那么你需要插你的X,Y,Z面到一个。你可以使用任何的统计学包(geoR,gstat,其他)或简单的技术与克里格做到这一点,如反距离加权。

If your x and y coords are not on a grid then you need to interpolate your x,y,z surface onto one. You can do this with kriging using any of the geostatistics packages (geoR, gstat, others) or simpler techniques such as inverse distance weighting.

我猜插值功能,您提到的就是从阿克玛包。需要注意的是输出矩阵是独立的输入点的大小。你可以有10000个在你的输入和内插了到一个10×10格,如果你想要的。默认情况下阿克玛::插值做它到一个40×40格:

I'm guessing the 'interp' function you mention is from the akima package. Note that the output matrix is independent of the size of your input points. You could have 10000 points in your input and interpolate that onto a 10x10 grid if you wanted. By default akima::interp does it onto a 40x40 grid:

> require(akima) ; require(rgl)
> x=runif(1000)
> y=runif(1000)
> z=rnorm(1000)
> s=interp(x,y,z)
> dim(s$z)
[1] 40 40
> surface3d(s$x,s$y,s$z)

这将看到高低不平和垃圾,因为它的随机数据。希望您的数据心不是!

That'll look spiky and rubbish because its random data. Hopefully your data isnt!

这篇关于R:从绘图X,Y,Z三维表面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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