简体   繁体   English

从 plotly 3d 图表创建视频

[英]create a video from plotly 3d chart

I'm wondering if anyone knows of a way to export plotly 3d charts as a video (more specifically if this can be done natively or requires bodging)?我想知道是否有人知道将 3d 图表导出为视频的方法(更具体地说,如果这可以在本地完成或需要 bodging)?

Exporting a static image is simple, and exporting the interactive plots is fine for embedding in HTML etc.导出静态图像很简单,导出交互式绘图非常适合嵌入 HTML 等。

Lets say I have a 3D chart that I want so simply rotate slowly, this seems like it could be pretty straight forward if the image can be rotated a given interval, an image taken, rotated further ad infinitum , perhaps in a loop - but I'm wondering if this isn't somehow supported natively?假设我有一个我想要的 3D 图表,所以只需缓慢旋转,如果图像可以旋转给定的时间间隔,拍摄的图像,无限旋转,可能是一个循环,这似乎很简单 - 但我想知道这是否不受本机支持?

Anyone know of a good strategy?有谁知道一个好的策略吗?

Solution ideally for R/RStudio, but since plotly is cross-platform, any solutions considered. R/RStudio 的理想解决方案,但由于 plotly 是跨平台的,因此可以考虑任何解决方案。

For future reference:供将来参考:

The key to being able to iterate multiple perspectives turns out to lie in the camera control "eye", the plotly help centre pointed me toward this:能够迭代多个视角的关键在于相机控制“眼睛”,情节帮助中心向我指出了这一点:

https://plot.ly/r/reference/#layout-scene-camera 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

This is kind of answered here, though searching for my specific query as above didn't find it:这是一种回答here,虽然搜索我上面的特定查询没有找到它:

enter link description here 在此处输入链接描述

I've used a for loop in the script to pass iterators to a trigonometric function that plots out a circle for the camera co-ordinates, rendering a new image at each step.我在脚本中使用了 for 循环将迭代器传递给三角函数,该函数为相机坐标绘制一个圆,在每一步渲染一个新图像。

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

在此处输入图片说明

The eventual code looked like this:最终的代码如下所示:

# 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 Number of files and the resolution of them could end up taking up a fair amount of space.注意文件的数量和它们的分辨率最终可能会占用相当多的空间。

NB 2 I had forgotten while constructing this that plotly's free API limits you to 50 API calls per day, so if you want to render a video, adjust your frames etc, accordingly... NB 2我在构建这个的时候忘记了,plotly 的免费 API 将你限制为每天 50 个 API 调用,所以如果你想渲染视频,相应地调整你的帧等......

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM