如何在 r 中绘制 3D 函数?
问题描述:
我有一个 3D 函数 - 比如说 De Jong 函数:
I have a function in 3D - let's say De Jong function:
fdejong <- function (x, y) {
return (x^2 + y^2)
}
如何以 3D 形式绘制它的图?我想从维基百科中实现类似的效果:
How can I draw it's plot in 3D? I want to achieve an effect similar to this from wikipedia:
答
您也可以使用 Lattice wireframe
功能.(使用@user1020027 的数据)
You can also use the Lattice wireframe
function. (Using @user1020027's data)
fdejong <- function (x, y) {
return (x^2 + y^2)
}
x <- seq(-10, 10, length= 30)
y <- x
z <- outer(x, y, fdejong)
z[is.na(z)] <- 1
require(lattice)
wireframe(z, drape=T, col.regions=rainbow(100))