来自2D矩阵的3D表面图 [英] 3D surface plot from 2D matrix
本文介绍了来自2D矩阵的3D表面图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在R中使用2d矩阵,如何创建3d表面图,其中column = x,rows = y,值是z的高度?
Using a 2d matrix in R, how can I create a 3d surface plot, where columns=x, rows=y and the values are the heights in z?
在下面的示例中,x值为1:5,y值为1:5,数字表示z中的高度/值.
In the example below, x values would be 1:5, y value would be 1:5, and the numbers would represent heights/values in z.
> m<-matrix(rnorm(25),nrow=5,ncol=5)
> m
[,1] [,2] [,3] [,4] [,5]
[1,] -1.495513045 0.8000040 -1.1499261 1.65661138 0.8140510
[2,] -1.150018195 -0.7582933 0.8306922 0.16026908 0.3913198
[3,] -0.852609406 0.5525621 0.3585986 -0.45054768 -1.2259927
[4,] -0.001926297 -0.5857351 2.1518281 0.03192463 0.2065039
[5,] -1.641128610 0.4333973 -1.0616628 -0.92143426 -0.9598991
推荐答案
软件包rgl
应该会让您入门...
Package rgl
should get you started...
require(rgl)
# open renderer
open3d()
# plot surface
rgl.surface( 1:10 , 1:10 , runif(100))
# Export to png
rgl.snapshot( "sample.png" , fmt="png", top=TRUE )
这篇关于来自2D矩阵的3D表面图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文