繁体   English   中英

Plotly 3D plot 在 python

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

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