簡體   English   中英

從 plotly 3d 圖表創建視頻

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM