[英]create a video from plotly 3d chart
我想知道是否有人知道将 3d 图表导出为视频的方法(更具体地说,如果这可以在本地完成或需要 bodging)?
导出静态图像很简单,导出交互式绘图非常适合嵌入 HTML 等。
假设我有一个我想要的 3D 图表,所以只需缓慢旋转,如果图像可以旋转给定的时间间隔,拍摄的图像,无限旋转,可能是一个循环,这似乎很简单 - 但我想知道这是否不受本机支持?
有谁知道一个好的策略吗?
R/RStudio 的理想解决方案,但由于 plotly 是跨平台的,因此可以考虑任何解决方案。
供将来参考:
能够迭代多个视角的关键在于相机控制“眼睛”,情节帮助中心向我指出了这一点:
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
这是一种回答here,虽然搜索我上面的特定查询没有找到它:
我在脚本中使用了 for 循环将迭代器传递给三角函数,该函数为相机坐标绘制一个圆,在每一步渲染一个新图像。
(x,y) = cos(theta) + sin(theta)
最终的代码如下所示:
# 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 = "X", titlefont = font.pref)
y.list <- list(title = "Y", titlefont = font.pref)
z.list <- list(title = "Z",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") %>%
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))))
# The above camera parameters should orbit
# horizontally around the chart.
# The multiplier controls how far out from
# from the graph centre the camera is (so
# is functionally a 'zoom' control).
graph
plotly_IMAGE(graph, username="xxx", key="xxx",
out_file = paste(outfile,"png", sep="."))
}
注意文件的数量和它们的分辨率最终可能会占用相当多的空间。
NB 2我在构建这个的时候忘记了,plotly 的免费 API 将你限制为每天 50 个 API 调用,所以如果你想渲染视频,相应地调整你的帧等......
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.