gpt4 book ai didi

r - R 中的 3d 绘图,更好的可见表面

转载 作者:行者123 更新时间:2023-12-04 04:52:24 25 4
gpt4 key购买 nike

用我的 data我使用以下代码创建:

library(rugarch)
library(fGarch)

fd <- as.data.frame(modelfit, which = 'density')

color <- rgb(85, 141, 85, maxColorValue=255)

x <- seq(-0.2, 0.2, length=100)
y <-c(1:2318)


f <- function(s, t) {
dged(s,mean=fd[t,'Mu'],sd=fd[t,'Sigma'],nu=fd[t,'Shape'])

}

z <- outer(x, y, f)

persp(x, y, z, theta=50, phi=25, expand=0.75, col=color,
ticktype="detailed", xlab="", ylab="time", zlab="density")
以下3d图:
3d
如您所见,表面看起来很乱。
所以我的第一个问题:
我怎样才能获得更好的可见表面?
我的第二个问题:
如何获得轴上的真实日期?目前我使用 c(1:2318),但在我的原始数据中
我可以通过命令查看行名中的日期 fd .那么如何在我的轴上获取这些日期呢?
编辑:另外:我怎样才能在我的情节中省略网格上的黑线?所以只有一个绿色的表面?那不是已经更好看了吗?

最佳答案

您可以尝试设置 shade=1border=NApersp称呼。

显示日期有点棘手,但可以通过使用 axes=FALSE 隐藏轴来完成。并通过使用 trans3d 找到合适的坐标来重新绘制它们功能。

这将给出类似的东西:

persp.mat <- persp(x, y, z, theta=50, phi=25, expand=0.75, col=color,
ticktype="detailed", xlab="", ylab="time", zlab="density",
shade=.4, border=NA, axes=F)

# The coords at which we want ticks
x.ticks <- seq(-0.2, 0.2, 0.1)
# Transform them in 3D
x.3d <- trans3d(x.ticks, 0, 0, persp.mat)
x.3d.1 <- trans3d(x.ticks, 0, -2, persp.mat)
# The coordinates for the text
x.3d.labels <- trans3d(x.ticks, -60, -3, persp.mat)
# Draw the axis ticks
segments(x.3d$x, x.3d$y, x.3d.1$x, x.3d.1$y)
# Write the labels
text(x.3d.labels$x, x.3d.labels$y, x.ticks, cex=0.8)

# Do the same for the other axes, customize the text labels
# to write dates

y.ticks <- seq(0, 2000, 500)
# Or whatever you like...
y.labels <- c("2009", "2010", "2011", "2012", "2013")
y.3d <- trans3d(0.2, y.ticks, 0, persp.mat)
y.3d.1 <- trans3d(0.2, y.ticks, -2, persp.mat)
y.3d.labels <- trans3d(0.22, y.ticks, -3, persp.mat)
segments(y.3d$x, y.3d$y, y.3d.1$x, y.3d.1$y)
text(y.3d.labels$x, y.3d.labels$y, y.labels, cex=0.8)

关于r - R 中的 3d 绘图,更好的可见表面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17252702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com