简体   繁体   English

R: plot 飞机在 3D

[英]R: plot a plane in 3D

I am trying to add the z=0 plane to a 3D plot.我正在尝试将 z=0 平面添加到 3D plot。 The code I use is我使用的代码是

library(plot3D)
zero = matrix(0, 20, 20)
persp3D(x=seq(1,20), y=seq(1,20), z = Delta_B, theta = 20, xlab = "D", ylab = "IR", zlab = "B increment")
persp3D(x=seq(1,20), y=seq(1,20), z = zero, col = "black", add = T)

But the z=0 plane does not appear.但是 z=0 平面没有出现。 在此处输入图像描述

If I jitter the plane with如果我让飞机抖动

zero = jitter(matrix(0, 20, 20))

Then I can see it properly.然后我可以正确地看到它。

在此处输入图像描述

In fact trying to plot the plane alone produces and empty graph.事实上试图 plot 飞机单独产生和空图。

persp3D(x=seq(1,20), y=seq(1,20), z = zero, col = "black")

在此处输入图像描述

EDIT编辑

A partial solution would be to use部分解决方案是使用

zero = jitter(matrix(0, 20, 20)) / 10000

which results in a plane that is indistinguishable from the intended one.这导致平面与预期的平面无法区分。

在此处输入图像描述

Something is failing whenever persp3D is presented with a constant matrix.每当persp3D呈现一个常数矩阵时,就会出现问题。 Usually this is because the software is trying to compute the scale of the Z range and divides by zero.通常这是因为软件试图计算 Z 范围的比例并除以零。 I'd only expect to see this when plotting a constant plane on its own though, not when adding one.我只希望在自己绘制一个恒定平面时看到这一点,而不是在添加一个平面时。

For example, base::persp will error:例如, base::persp会报错:

> persp(zero)
Error in persp.default(zero) : invalid 'z' limits

If you want a fully reproducible example, create a Delta_B thus:如果您想要一个完全可重现的示例,请创建一个Delta_B

> Delta_B = matrix(apply(expand.grid(1:20,1:20),1,function(r){sum(r)-20}),20,20)

Then:然后:

> persp3D(x=seq(1,20), y=seq(1,20), z = Delta_B, theta = 20, xlab = "D", ylab = "IR", zlab = "B increment")
> zero = matrix(0, 20, 20)
> persp3D(x=seq(1,20), y=seq(1,20), z = zero, col = "black", add = TRUE)

Does not show the zero plane.不显示zero平面。 But anything that makes the zero matrix non-constant will fix it:但是任何使zero矩阵非常数的东西都会修复它:

> zero[1,1]=0.000001
> persp3D(x=seq(1,20), y=seq(1,20), z = zero, col = "black", add = TRUE)

That should be sufficient to submit a bug report to the maintainer.这应该足以向维护者提交错误报告。 The code for persp3D is a lengthy bit of code which I'm not digging into now. persp3D的代码是一段很长的代码,我现在不会深入研究。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM