形成persp3d图 [英] Formating of persp3d plot

查看:277
本文介绍了形成persp3d图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下3d图表:

使用我的数据我使用以下代码创建了它:

With my data I created it with the following code:

library(rugarch)
library(rgl)
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)
persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=color,
      ticktype="detailed", xlab="", ylab="time", zlab="",axes=TRUE)

如何根据z值得到一个着色?我看了不同的解决方案,例如。此一个,但我无法创建着色取决于这种情况下的z值。
根据此主题的解决方案将是以下内容:

How can I get a coloring depending on the z values? I looked at different solutions, e.g. this one, but I could not create the coloring depending on the z values in this case. The solution according to this thread would be the following:

nrz <- nrow(z)
ncz <- ncol(z)
jet.colors <- colorRampPalette( c("#ffcccc", "#cc0000") ) 
# Generate the desired number of colors from this palette
nbcol <- 100
color <- jet.colors(nbcol)

# Compute the z-value at the facet centres
zfacet <- z[-1, -1] + z[-1, -ncz] + z[-nrz, -1] + z[-nrz, -ncz]
# Recode facet z-values into color indices
facetcol <- cut(zfacet, nbcol)

  persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=color[facetcol],
          ticktype="detailed", xlab="", ylab="time", zlab="",axes=TRUE)

没有给出一个好的结果,因为它不着色的情节适当。我想让我的表面的尖峰例如。为红色,低值为例如。在蓝色与一个很好的平滑过渡,但这种颜色的切片,所以取决于时间?因此,极大的尖峰应当在其尖峰处着色为红色,而在底部处的值例如。在绿色。我如何获得这个?

But this does not give a good result, since it does not color the plot appropriate. I want to have the spikes of my surface to be e.g. in red and the low values to be e.g. in blue with a nice smooth transition, but this kind of colors the slices, so depending on the time? So extreme large spikes should be colored at their spikes in red and values at the bottom e.g. in green. How can I get this?

编辑:我发现一个解决方案,我上一个问题关于轴上的日期,唯一的问题是,是一个适当的着色取决于z值。

I found a solution to my previous question about the date on the axis, the only problem left, is an appropriate coloring dependent on the z values.

推荐答案

尝试:

nbcol = 100
color = rev(rainbow(nbcol, start = 0/6, end = 4/6))
zcol  = cut(z, nbcol)
persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=color[zcol],
        ticktype="detailed", xlab="", ylab="time", zlab="",axes=TRUE)

如果你想让颜色按时间(所以峰值总是红色),你可以设置每个时间片:

If you want the coloring to be by time (so spikes are always red) you can set the coloring for each time slice:

mycut = function(x, breaks) as.numeric(cut(x=x, breaks=breaks)) # to combine different factors
zcol2 = as.numeric(apply(z,2, mycut, breaks=nbcol)) 
persp3d(x, y, z, theta=50, phi=25, expand=0.75, col=color[zcol2],
        ticktype="detailed", xlab="", ylab="time", zlab="",axes=TRUE)

您已经知道如何正确编辑轴。

You already know how to edit the axes properly.

这篇关于形成persp3d图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆