我有许多长度不同的2D序列,即列表的列表,其中每个子列表都是一个序列。我想在三维可视化中将这些序列/行/子列表投影出来,并添加时间步作为另一维。到目前为止,我未能使用
这是我得到的结果,不是我真正想要的。它将所有具有共同标签的情况/子列表视为一个单一序列,因此我们在每行末尾看到它回到起点。我已经查找了如何在for循环中迭代绘制它(就像matplotlib一样)(基本上在每次迭代时创建一个新的pandas数据帧并绘制它),但没有成功。请问有人有相关经验吗?非常感谢! 一份简历如下:
你看到的基本上是3行而不是5行。
plotly.express
绘制所有3D线条。import plotly.express as px
t = [[ii+1 for ii in range(len(features[i]))] for i in range(len(labels))]
x0 = [[x[0] for x in features[i]] for i in range(len(labels))]
x1 = [[x[1] for x in features[i]] for i in range(len(labels))]
df = pd.DataFrame(dict(
X=[tii for ti in t for tii in ti],
Y=[xii for xi in x0 for xii in xi],
Z=[xii for xi in x1 for xii in xi],
color=[aa for a in labels for aa in a]
))
fig = px.line_3d(df, x="X", y="Y", z="Z", color="color")
fig.show
这是我得到的结果,不是我真正想要的。它将所有具有共同标签的情况/子列表视为一个单一序列,因此我们在每行末尾看到它回到起点。我已经查找了如何在for循环中迭代绘制它(就像matplotlib一样)(基本上在每次迭代时创建一个新的pandas数据帧并绘制它),但没有成功。请问有人有相关经验吗?非常感谢! 一份简历如下:
import plotly.express as px
import numpy as np
import pandas as pd
features = [np.random.rand(4,2).tolist(),
np.random.rand(5,2).tolist(),
np.random.rand(6,2).tolist(),
np.random.rand(5,2).tolist(),
np.random.rand(9,2).tolist()]
labels = [[1, 1, 1, 1], [1, 1, 1, 1, 1], [2, 2, 2, 2, 2, 2],
[2, 2, 2, 2, 2], [0, 0, 0, 0, 0, 0, 0, 0, 0]]
t = [[ii+1 for ii in range(len(features[i]))] for i in range(len(labels))]
x0 = [[x[0] for x in features[i]] for i in range(len(labels))]
x1 = [[x[1] for x in features[i]] for i in range(len(labels))]
df2 = pd.DataFrame(dict(
X=[tii for ti in t for tii in ti],
Y=[xii for xi in x0 for xii in xi],
Z=[xii for xi in x1 for xii in xi],
color=[aa for a in labels for aa in a]
))
fig1 = px.line_3d(df2, x="X", y="Y", z="Z", color="color")
fig1.show()
你看到的基本上是3行而不是5行。
features
并没有被定义。你介意提供一个mcve吗? - undefinedpx
,第一组标签[1,1,...]
和第二组是一样的。 - undefined