[英]Plotly 3D plot in python
我想使用 plotly 在 python 中制作 3D plot。 Actually its the first step of an animation but first I need to know how to create a 3D scatter plot of it as shown below which is made in matplotlib. 我有看起來像這樣的數據集。
現在,我想根據提到的日期對其進行動畫處理,但是我在 plotly 的官方網站上獲得的代碼是這樣的,其中大多數是相似的。
import plotly.express as px
df = px.data.iris()
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
color='species')
fig.show()
現在,我無法理解如何分配X,Y and Z
來獲得動畫 plot。 因為我需要在 plot 中對日期的所有 13 列。
作為參考,我發現這個網站說,
To get a 3D scatter plot you need to specify the trace as a plotly.graph_objs.Scatter3d object or as a dict with a type: 'scatter3d' key.
Feel free to share a full reproducible example if you’d like to work through more of the details.
但這還不夠。
請幫我解決一下這個。 正確代碼或指導的鏈接對於如何設置變量以獲取 3D plot animation非常有幫助。 謝謝你。
為了更新 plotly 中的現有繪圖,它們具有FigureWidget
接口。 如果您可以在小部件工作的環境(例如 Jupyter notebook)中操作,那么以下代碼將重復更新現有 plot 中的數據。
它看起來不像animation 。 如果在您旋轉視圖時數據更新,它會猛拉回原來的 position。 所以這不是很好。 但是,如果您對這些限制沒意見,這將使您入門。
import plotly.express as px
df = px.data.iris()
fig = px.scatter_3d(df, x='sepal_length', y='sepal_width', z='petal_width',
color='species')
import threading
import time
import numpy as np
fw = go.FigureWidget(fig)
def do():
while True:
fw.data[0]['x'] = np.random.rand(len(fw.data[0]['x']))
time.sleep(1)
t = threading.Thread(target=do)
t.start()
fw # run this in cell after which the plot will be generated.
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.