python how to draw a 3D figure using a 3D array?

ax = plt.axes(projection ="3d")
plt.figure()

ax.scatter(res[???],s=2,color="red")
plt.show()

res.shape

(3438, 3)

res

array([[-0.37735112,  0.70916688, -0.11611093],
       [-1.65987721,  0.36333406, -0.15776237],
       [ 0.04139574, -0.6512135 ,  0.58187669],
       ...,
       [ 1.70450881,  3.08870729,  0.53986034],
       [-0.31678427, -0.59254118,  0.20142223],
       [-0.21731326, -0.92191064, -0.18022078]])

 

 

试下这个

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax = fig.add_subplot(projection='3d')

ar = np.array([[-0.37735112,  0.70916688, -0.11611093],
       [-1.65987721,  0.36333406, -0.15776237],
       [ 0.04139574, -0.6512135 ,  0.58187669],
       [ 1.70450881,  3.08870729,  0.53986034],
       [-0.31678427, -0.59254118,  0.20142223],
       [-0.21731326, -0.92191064, -0.18022078]])


ax.scatter(ar[:,0], ar[:,1], ar[:,2])

ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

plt.show()

 

参考这个试试:https://blog.csdn.net/weixin_39771351/article/details/111293632

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from mpl_toolkits.mplot3d import Axes3D
>>> data = np.array([[-0.37735112,  0.70916688, -0.11611093],
       [-1.65987721,  0.36333406, -0.15776237],
       [ 0.04139574, -0.6512135 ,  0.58187669],
       [ 1.70450881,  3.08870729,  0.53986034],
       [-0.31678427, -0.59254118,  0.20142223],
       [-0.21731326, -0.92191064, -0.18022078]])
>>> fig = plt.figure()
>>> ax = fig.add_axes((0.1,0.1,0.8,0.8), projection='3d')
>>> ax.scatter3D(data[:,0], data[:,1], data[:,2], s=20, c=np.abs(data[:,0]))
<mpl_toolkits.mplot3d.art3d.Path3DCollection object at 0x00000183DC176D88>
>>> plt.show()

 

scatter3D的s参数指定点的大小,c参数指定每个点的颜色。这里用每个点的x坐标的绝对值表示颜色,题主可以自行替换。效果如下:

import numpy as np
from matplotlib import pyplot as plt

res = np.array([[-0.37735112,  0.70916688, -0.11611093],
       [-1.65987721,  0.36333406, -0.15776237],
       [ 0.04139574, -0.6512135 ,  0.58187669],
       [ 1.70450881,  3.08870729,  0.53986034],
       [-0.31678427, -0.59254118,  0.20142223],
       [-0.21731326, -0.92191064, -0.18022078]])
res.tolist()
x, y, z = [], [], []
for i in res:
    x.append(i[0])
    y.append(i[1])
    z.append(i[2])

fig = plt.figure()
ax1 = plt.axes(projection='3d')
ax1.scatter3D(x, y, z)# 绘制散点图
plt.show()

 

如果满意,请采纳,谢谢!

画一个点:

import numpy as np
from matplotlib import pyplot as plt

fig = plt.figure()
ax1 = plt.axes(projection='3d')
ax1.scatter3D(10,20,10)# 绘制散点图
plt.show()

 

这里好热闹!我再来贡献一个。

>>> import wxgl.wxplot as plt
>>> import numpy as np
>>> vs = np.random.random(90).reshape((30,3))
>>> plt.scatter(vs, color=None, size=5, cmap='hsv', caxis='z')
>>> plt.show()

 

效果如下:

您好,我是有问必答小助手,你的问题已经有小伙伴为您解答了问题,您看下是否解决了您的问题,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632

谢谢各位的帮忙,我不知道只能采纳一位老师的回复,所以从最顶的回复开始点的,然后 后面的就不能点了。。。。