问题描述
我有一些麻烦,产生从数据帧的每一行.png格式。
基本上,我想 rbind
的行中的每一个DF
到 coordinate_sys
。
有关的每一行DF
与 coordinate_sys
在一起,坐标系统和一个单位向量J应像<一个生成href=\"http://stackoverflow.com/questions/34186711/rgl-vector-diagrams-show-right-angles-for-orthogonal-vectors?rq=1\">this
最后,产生每个unit_vector .png文件后,我想提出.gif注意动画。
这里是我的脚本的可重复code;
库(matlib)
库(RGL)
set.seed(12)
X - 下; - runif(10,-0.14,0.1)
Y'LT; - runif(10 -0.14,0.1)
z,其中,-sort(runif(10,-0.9,0.9),降低= TRUE)
DF&LT; - data.frame(X,Y,Z)
腐&LT; - 功能(DF,出来){
coordinate_sys&LT; - rbind(C(1,0,0),C(0,-1,0),C(0,0,1))
VEC&LT; - rbind(coordinate_sys,不公开(DF))
rownames(VEC)下; - C(X,Y,Z,J)
打印(vectors3d(VEC,COL = C(REP(黑,3),红),LWD = 2))
出&LT; - PNG(文件=榜样%02d.png,宽度= 200,高度= 200)
dev.off()
}申请(DF,1,腐烂了)
这是多远我得到了:
腐&LT; - 功能(DAT,我){
coordinate_sys&LT; - rbind(C(1,0,0),C(0,-1,0),C(0,0,1))
VEC&LT; - rbind(coordinate_sys,不公开(DAT))
rownames(VEC)下; - C(X,Y,Z,J)
open3d()
PLOT3D(1,XLIM = C(-1,1),ylim = C(-1,1),zlim = C(-1,1),类型='N')
打印(vectors3d(VEC,COL = C(REP(黑,3),红),LWD = 2))
rgl.snapshot(paste0(字母[I],png格式))
rgl.close()
}mapply(腐,分割(DF,1:nrow(DF)),I = 1:nrow(DF))
这code将生成一个向量10巴纽图像在每一个稳定的坐标系。 (这虽然会产生警告。)
现在,我们应该能够使该到使用动画包一个.gif,但它在我的机器上的失败,因为ImageMagick的不想读.png文件(?)。也许它会工作的梦想。
库(动画)
im.convert('*。PNG)
I have some trouble with generating .png from each rows of data frame.
Basically, I want to rbind
each one of the row of df
to coordinate_sys
.
For each row of df
together with coordinate_sys
, a coordinate system and one a unit vector "J" should be generated like in this
Finally, after generating a .png file for each unit_vector, I would like to make .gif animation.
here is the reproducible code of my script;
library(matlib)
library(rgl)
set.seed(12)
x <- runif(10,-0.14,0.1)
y <- runif(10,-0.14,0.1)
z <-sort(runif(10,-0.9,0.9),decreasing=TRUE)
df <- data.frame(x,y,z)
rot <- function(df,out){
coordinate_sys <- rbind(c(1,0,0),c(0,-1,0),c(0,0,1))
vec <- rbind(coordinate_sys, unlist(df))
rownames(vec) <- c("X", "Y", "Z", "J")
print(vectors3d(vec, col=c(rep("black",3), "red"), lwd=2))
out <- png(file="example%02d.png", width=200, height=200)
dev.off()
}
apply(df, 1,rot,out)
This is how far I got:
rot <- function(dat, i){
coordinate_sys <- rbind(c(1,0,0),c(0,-1,0),c(0,0,1))
vec <- rbind(coordinate_sys, unlist(dat))
rownames(vec) <- c("X", "Y", "Z", "J")
open3d()
plot3d(1, xlim = c(-1, 1), ylim = c(-1, 1), zlim = c(-1, 1), type = 'n')
print(vectors3d(vec, col=c(rep("black",3), "red"), lwd=2))
rgl.snapshot(paste0(letters[i], '.png'))
rgl.close()
}
mapply(rot, split(df, 1:nrow(df)), i = 1:nrow(df))
This code will generate 10 .png images with one vector in each and a stable coordinate system. (It generates warnings though.)
Now, we should be able to make that into a .gif using the animation package, but it fails on my machine due ImageMagick not wanting to read .png files (?). Perhaps it will work on yours.
library(animation)
im.convert('*.png')
这篇关于的.png输出data.frame的每一行,使.gif注意动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!