I'm trying to create a 3D plot of a function, but the message "Error in persp.default(x = xseq, y = yseq, matrixz, phi = -5, theta = 50, : incorrect z limits" appears. I have no idea why
yseq <- seq(1e-9,1e-7,by=1e-9)
xseq <- seq(1e-8,1e-4,by=1e-6)
matrixz <- matrix(data = 0,nrow=length(xseq),ncol=length(yseq))
persp(x=xseq,y=yseq, matrixz, phi=-5, theta=50, expand=0.5, col="red4",xlab="[Ca] cytosol",ylab="[InsP3]",zlab="J2(x,y)", ticktype="detailed")
Any help would be greatly appreciated !
Well, the matrixz
is only filled with 0s and the range
of it, does not please persp
and explains your error message:
> range(matrixz)
[1] 0 0
You can fix this by defining a zlim
:
yseq <- seq(1e-9, 1e-7, by=1e-9)
xseq <- seq(1e-8, 1e-4, by=1e-6)
matrixz <- matrix(data =0, nrow=length(xseq), ncol=length(yseq))
persp(xseq, yseq, matrixz, phi=-5, zlim=c(-1e-3, 1e-3),
theta=50, expand=0.5, col="red4",xlab="[Ca] cytosol",ylab="[InsP3]",zlab="J2(x,y)",
ticktype="detailed")
or by filling your matrix, with your data. Here we sample numbers from the uniform distribution:
matrixz <- matrix(data = runif(length(xseq)*length(yseq)), nrow=length(xseq), ncol=length(yseq))
persp(xseq, yseq, matrixz, phi=-5, theta=50, expand=0.5,
col="red4",xlab="[Ca] cytosol",ylab="[InsP3]",zlab="J2(x,y)",
ticktype="detailed")
If you don't want to bother with a particular theta
, phi
, etc. you can explore your 3D plot with persp3d
from rgl
:
library(rgl)
persp3d(xseq, yseq, matrixz)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.