在 python 中将 2D 图形转换为 3D

Turning 2D graphics into 3D in python

在 2D 中,我的 x 获取 x 和 y 坐标的值:

x = [[0.72,0.82]]

在代码中的某些时候我使用了这个:

plt.plot(x[i][0], x[i][1], 'go', markersize=15, alpha=.5)

现在我有一个 x 可以获取 x、y 和 z 坐标的值:

x = [[0.72,0.82,-0.77]]

而且我现在只想在 3D 中重现 2D 的相同效果,我尝试这样做:

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.set_xlim(-1, 1)
ax.set_ylim(-1, 1)
ax.set_zlim(-1, 1)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')

ax.scatter(x[i][0], x[i][1], x[i][2], 'go', markersize=15, alpha=.5)

但我收到以下错误:

AttributeError: Unknown property markersize

P.S.: 我正在使用:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

我想知道如何正确绘制它们。

检查 matplotlib reference 中的 ax.scatter 参数,markerzisealpha 不存在,要更改点的大小,您应该使用 s 参数,一些东西喜欢:

ax.scatter(xs, ys, zs, s=10, c=c, marker=m)

注意 s 也可以是与 xs 长度相同的数组,如果您希望点的大小与其 xs 值成正比。