带有 numpy 数组的交互式 3D 图

Interactive 3D plot with numpy array

我一直在使用 plotly 进行数据帧可视化,但是当数据类型为数组时,除了将数组转换为数据帧之外,创建交互式绘图的最佳方法是什么?

我之前用于数据框的代码:

import plotly.express as px

fig = px.scatter_3d(df, x='col1', y='col2', z='col3',)

fig.update_traces(marker=dict(size=2,
                         line=dict(width=0.01)
                             )
                 )

fig.update_layout(showlegend=True, 
                  width=900, 
                  height=900,
                  title = 'My Plot')
fig.show()

如果您的意思是您有一个 numpy 数组,其列(或行)给出了您要绘制的点的坐标,那么您可以将这些列分配给 xyz 个参数:

import plotly.express as px
import numpy as np

X = np.random.randint(0, 10, (10, 3))
fig = px.scatter_3d(x=X[:,0], y=X[:, 1], z=X[:, 2])
fig.show()