3D surface plot from 2D matrix

后端 未结 2 1613
广开言路
广开言路 2020-12-31 08:36

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?

In the example below, x values would be 1:5,

相关标签:
2条回答
  • 2020-12-31 09:08

    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 )
    

    enter image description here

    0 讨论(0)
  • 2020-12-31 09:11

    To get a 3D surface plot of a 2D matrix that contains the Z-values, try:

    require(plot3D)
    
    persp3D(z = TheMatrix2D, theta = 120)
    

    Use theta to adjust the viewing angle. With my data, I get the following plot:

    0 讨论(0)
提交回复
热议问题