从情节三维图表创建视频

时间:2016-08-30 13:01:12

标签: r plotly

我想知道是否有人知道将三维图表作为视频导出的方法(更具体地说,如果这可以原生或需要躲避)?

导出静态图像很简单,导出交互式图表可以嵌入HTML等。

假设我有一个我想要的3D图表,所以只需简单地旋转,如果图像可以旋转给定的间隔,拍摄的图像,进一步旋转 ad infinitum,这似乎非常简单。 em>,也许是一个循环 - 但我想知道这是不是以某种方式本地支持?

任何人都知道一个好的策略吗?

理想情况下是R / RStudio的解决方案,但由于情节是跨平台的,所以考虑任何解决方案。

1 个答案:

答案 0 :(得分:1)

供将来参考:

能够迭代多个视角的关键在于摄像机控制“眼睛”,故事帮助中心指向我:

https://plot.ly/r/reference/#layout-scene-camera

camera = list(eye = list(x = 1.25, y = 1.25, z = 1.25))) #1.25 is default

这里有点回答,虽然如上所述搜索我的特定查询却找不到它:

http://stackoverflow.com/questions/34178381/how-to-specify-camera-perspective-of-3d-plotly-chart-in-r

我在脚本中使用了for循环来将迭代器传递给三角函数,该函数绘制了一个用于摄像机坐标的圆,在每一步渲染一个新图像。

(x,y)= cos(theta)+ sin(theta)

enter image description here

最终的代码如下所示:

# assume dataset read in, manipulated and given as a matrix in "matrix"
matrix.list <- list(
                x = temp,
                y = scan,
                z = matrix
                )
font.pref <- list(size=12,family="Arial, sans-serif",color="black")
x.list <- list(title = "Temperature (˚C)",titlefont = font.pref)
y.list <- list(title = "Wavelength (nm)",titlefont = font.pref)
z.list <- list(title = "CD Intensity",titlefont = font.pref)
zoom <- 2
for(i in seq(0,6.3,by=0.1){ # 6.3 is enough for a full 360 rotation
outfile <- paste(file,"plot",i, sep = "_")

graph <- plot_ly(matrix.list,x = temp,y = scan,z = z,
                 type="surface",
                 colors=c("black","grey","red"),
                 colorbar = list(title="CD Intensity")) %>%
                  layout(scene=list(xaxis = x.list,
                                    yaxis = y.list,
                                    zaxis = z.list,
                                    camera = list(eye = list(x = cos(i)*zoom, y = sin(i)*zoom, z= 0.25)))) # Should orbit horizontally around the chart, the multiplier just controls how far out from the graph centre the camera is.
graph

plotly_IMAGE(graph,
             width = 1600,
             height = 1400,
             format = "png",
             username="xxx",
             key="xxx",
             scale = 1,
             out_file = paste(outfile,"png", sep="."))
}

NB 文件数量及其分辨率可能会占用相当大的空间。

NB 2 我在构建时忘记了这个情节的免费API限制你每天50个API调用,所以如果你想渲染一个视频,调整你的帧等,相应... < / p>