在 3D space 中绘制 (x,y,z) 点的二维数组 (Matplotlib)
Plot 2D array of (x,y,z) points in 3D space (Matplotlib)
我是 Python 的初学者,尤其是 Matplotlib。我有一个 22797x3 数组,由另外两个数组相乘而成,一个 22797x400 长,另一个 400x3 长。在结果数组 (22797x3) 中,每行代表一个具有 (x,y,z) 坐标的点,因此有 3 列。我如何在 3D 表面上绘制结果数组,我可以在其中看到 3D space 中分布的所有 22797 个点?此数据用于将来的 Kmeans 聚类,因此我需要将其可视化。
到目前为止我已经尝试过:
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
#building the 22797x3 array:
#loading the first array from .txt file, 22797x400 long.
array = np.loadtxt('C:\Users\Scripts/final_array.txt', usecols=range(400))
array = np.float32(array)
#loading the second array from .txt file, 400x3 long.
small_vh2 = np.loadtxt('C:\Users\Scripts/small_vh2.txt', usecols=range(3))
small_vh2 = np.float32(small_vh2)
#multiplying and getting result array 22797x3 long:
Y = np.array(np.matmul(array,small_vh2))
#I've checked Y dimensions, it's 22797x3 long, working fine.
#now I must plot it in 3D:
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2])
plt.show()
我不断得到如下图所示的结果:
https://i.stack.imgur.com/jRyHM.jpg
我需要的是得到22797点,而我一直得到只绘制了4点。有人知道代码有什么问题吗?
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from matplotlib import pyplot as plt
# made 2 random arrays of the same size as yours
array = np.random.rand(22797, 400)
small_vh2 = np.random.rand(400,3)
Y = np.matmul(array,small_vh2)
#now I must plot it in 3D:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2], alpha = 0.1)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()
我是 Python 的初学者,尤其是 Matplotlib。我有一个 22797x3 数组,由另外两个数组相乘而成,一个 22797x400 长,另一个 400x3 长。在结果数组 (22797x3) 中,每行代表一个具有 (x,y,z) 坐标的点,因此有 3 列。我如何在 3D 表面上绘制结果数组,我可以在其中看到 3D space 中分布的所有 22797 个点?此数据用于将来的 Kmeans 聚类,因此我需要将其可视化。
到目前为止我已经尝试过:
import numpy as np
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
#building the 22797x3 array:
#loading the first array from .txt file, 22797x400 long.
array = np.loadtxt('C:\Users\Scripts/final_array.txt', usecols=range(400))
array = np.float32(array)
#loading the second array from .txt file, 400x3 long.
small_vh2 = np.loadtxt('C:\Users\Scripts/small_vh2.txt', usecols=range(3))
small_vh2 = np.float32(small_vh2)
#multiplying and getting result array 22797x3 long:
Y = np.array(np.matmul(array,small_vh2))
#I've checked Y dimensions, it's 22797x3 long, working fine.
#now I must plot it in 3D:
fig = plt.figure()
ax = Axes3D(fig)
ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2])
plt.show()
我不断得到如下图所示的结果:
https://i.stack.imgur.com/jRyHM.jpg
我需要的是得到22797点,而我一直得到只绘制了4点。有人知道代码有什么问题吗?
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
from matplotlib import pyplot as plt
# made 2 random arrays of the same size as yours
array = np.random.rand(22797, 400)
small_vh2 = np.random.rand(400,3)
Y = np.matmul(array,small_vh2)
#now I must plot it in 3D:
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(Y[:, 0], Y[:, 1], Y[:, 2], alpha = 0.1)
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')
plt.show()