如何保留旋转晶格云散点图的比例?

发布于 2024-10-25 07:08:40 字数 2505 浏览 4 评论 0原文

背景:我正在尝试使用 R 的lattice::cloud() 函数来制作旋转3D 散点图的动画。我在 R 中创建了一系列 PNG 图像,然后根据该序列创建了一个动画 GIF。

问题在于绘图的比例随着旋转而变化,因此动画立方体在旋转时看起来会增大和缩小。

这是仅使用两个图的示例(基于云示例之一):

library(lattice)
par.set <-
  list(axis.line = list(col = "transparent"),
     clip = list(panel = "off"))

print(cloud(Sepal.Length ~ Petal.Length * Petal.Width, 
    data = iris, cex = .8, 
    groups = Species, 
    screen = list(z = 0, x = 0, y = 0),
    par.settings = par.set,
    scales = list(col = "black")),
  split = c(1,1,2,1), more = TRUE)
print(cloud(Sepal.Length ~ Petal.Length * Petal.Width,
    data = iris, cex = .8, 
    groups = Species,
    screen = list(z = 0, x = 0, y = 30),
    par.settings = par.set,
    scales = list(col = "black")),
  split = c(2,1,2,1))

我希望右侧图的大小与左侧图的大小相同。在此示例中,它要小得多。我不必使用 R 或lattice::cloud(),但它非常接近我想要的...

尝试 rgl,看起来也许我的 rgl 副本与我的 R 版本不兼容。我会升级R,当我有时间时:

> library(rgl)
> df <- data.frame(x=runif(10,0,1), y=runif(10,0,1), z=runif(10,0,1), color=round(runif(10,1,3)))
> plot3d(df$x, df$y, df$z, col=df$color, size=2, type='s')
> rgl.snapshot("C:\\pic.png", fmt="png", top=TRUE )
[1] "failed"
Warning messages:
1: In rgl.snapshot("C:\\pic.png", fmt = "png", top = TRUE) :
  RGL: PNG Pixmap Saver Warning: Application was compiled with png.h from libpng-1.2.40
2: In rgl.snapshot("C:\\pic.png", fmt = "png", top = TRUE) :
  RGL: PNG Pixmap Saver Warning: Application  is  running with png.c from libpng-1.4.1
3: In rgl.snapshot("C:\\pic.png", fmt = "png", top = TRUE) :
  RGL: PNG Pixmap Saver Warning: Incompatible libpng version in application and library

> sessionInfo()
R version 2.11.1 (2010-05-31) 
i386-pc-mingw32 

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rgl_0.92.798

loaded via a namespace (and not attached):
[1] tools_2.11.1

我更新到 R 2.12.2,现在可以使用(使用 GraphicsMagick 而不是 ImageMagick):

open3d()
with(iris, plot3d(Petal.Length, Petal.Width, Sepal.Length, col=Species))
movie3d(spin3d(), duration=12, dir="C:\\Movie", convert=FALSE)
system('"C:\\program files\\graphicsmagick-1.3.7-q8\\gm.exe" convert -delay 12 C:\\Movie\\movie*.png C:\\Movie\\animate.gif')

Background: I am trying to animate a rotating 3D scatter plot using R's lattice::cloud() function. I create a sequence of PNG images in R, then create an animated GIF from the sequence.

The problem is that the scale of the plot changes with rotation so the animated cube appears to grow and shrink as it turns.

Here is an example using just two plots (based on one of the cloud examples):

library(lattice)
par.set <-
  list(axis.line = list(col = "transparent"),
     clip = list(panel = "off"))

print(cloud(Sepal.Length ~ Petal.Length * Petal.Width, 
    data = iris, cex = .8, 
    groups = Species, 
    screen = list(z = 0, x = 0, y = 0),
    par.settings = par.set,
    scales = list(col = "black")),
  split = c(1,1,2,1), more = TRUE)
print(cloud(Sepal.Length ~ Petal.Length * Petal.Width,
    data = iris, cex = .8, 
    groups = Species,
    screen = list(z = 0, x = 0, y = 30),
    par.settings = par.set,
    scales = list(col = "black")),
  split = c(2,1,2,1))

I would like the right-hand plot to appear the same size as the left-hand plot. In this example it is quite a bit smaller. I don't have to use R or lattice::cloud() but it is very close to what I want...

Trying rgl, it looks like maybe my copy of rgl is incompatible with my version of R. I'll upgrade R when I have a minute:

> library(rgl)
> df <- data.frame(x=runif(10,0,1), y=runif(10,0,1), z=runif(10,0,1), color=round(runif(10,1,3)))
> plot3d(df$x, df$y, df$z, col=df$color, size=2, type='s')
> rgl.snapshot("C:\\pic.png", fmt="png", top=TRUE )
[1] "failed"
Warning messages:
1: In rgl.snapshot("C:\\pic.png", fmt = "png", top = TRUE) :
  RGL: PNG Pixmap Saver Warning: Application was compiled with png.h from libpng-1.2.40
2: In rgl.snapshot("C:\\pic.png", fmt = "png", top = TRUE) :
  RGL: PNG Pixmap Saver Warning: Application  is  running with png.c from libpng-1.4.1
3: In rgl.snapshot("C:\\pic.png", fmt = "png", top = TRUE) :
  RGL: PNG Pixmap Saver Warning: Incompatible libpng version in application and library

> sessionInfo()
R version 2.11.1 (2010-05-31) 
i386-pc-mingw32 

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rgl_0.92.798

loaded via a namespace (and not attached):
[1] tools_2.11.1

I updated to R 2.12.2 and now this works (using GraphicsMagick instead of ImageMagick):

open3d()
with(iris, plot3d(Petal.Length, Petal.Width, Sepal.Length, col=Species))
movie3d(spin3d(), duration=12, dir="C:\\Movie", convert=FALSE)
system('"C:\\program files\\graphicsmagick-1.3.7-q8\\gm.exe" convert -delay 12 C:\\Movie\\movie*.png C:\\Movie\\animate.gif')

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错々过的事 2024-11-01 07:08:40

尝试 rgl 包,这就是我处理相同现象的方法,

require ("rgl")

df <- data.frame(x=runif(10,0,1), y=runif(10,0,1), z=runif(10,0,1), color=round(runif(10,1,3)))

plot3d(df$x, df$y, df$z, col=df$color, size=2, type='s')

?movie3d()

demo(flag)

test <- spin3d(rpm=6,axis=c(0,0,1))
?spin3d

open3d()
plot3d(oh3d(col="lightblue", alpha=0.5))
play3d(spin3d(axis=c(0,0,1), rpm=20), duration=3)


open3d()
plot3d( cube3d(col="green") )
M <- par3d("userMatrix")
play3d( par3dinterp( userMatrix=list(M,
                                 rotate3d(M, pi/2, 1, 0, 0),
                                 rotate3d(M, pi/2, 0, 1, 0) ) ), 
    duration=4 )

movie3d( spin3d(), duration=5 )

我的会话信息是一个已确认的工作示例。

R version 2.12.2 (2011-02-25)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rgl_0.92.798

loaded via a namespace (and not attached):
[1] tools_2.12.2

Try the rgl package, this is how I approached the same phenomea

require ("rgl")

df <- data.frame(x=runif(10,0,1), y=runif(10,0,1), z=runif(10,0,1), color=round(runif(10,1,3)))

plot3d(df$x, df$y, df$z, col=df$color, size=2, type='s')

?movie3d()

demo(flag)

test <- spin3d(rpm=6,axis=c(0,0,1))
?spin3d

open3d()
plot3d(oh3d(col="lightblue", alpha=0.5))
play3d(spin3d(axis=c(0,0,1), rpm=20), duration=3)


open3d()
plot3d( cube3d(col="green") )
M <- par3d("userMatrix")
play3d( par3dinterp( userMatrix=list(M,
                                 rotate3d(M, pi/2, 1, 0, 0),
                                 rotate3d(M, pi/2, 0, 1, 0) ) ), 
    duration=4 )

movie3d( spin3d(), duration=5 )

My session info for a confirmed working example.

R version 2.12.2 (2011-02-25)
Platform: i386-pc-mingw32/i386 (32-bit)

locale:
[1] LC_COLLATE=English_United States.1252 
[2] LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] rgl_0.92.798

loaded via a namespace (and not attached):
[1] tools_2.12.2
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文