Python 用 matplotlib 绘制 3D 散点图
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d
from mpl_toolkits.mplot3d import Axes3D
m= np.array([[1,3,3],
[4,1,6],
[1,4,2],
[1,6,3]])
x = [i[0] for i in m]
y = [i[1] for i in m]
z = [2,2,2,3]
z1 = [i[2] for i in m]
print(x,y,z)
print(m)
# 标准
fig = plt.figure()
ax = fig.add_subplot(121,projection = '3d')
ax.set_title('3d_image_show',fontsize=20)
ax.scatter(x, y, z,c='r',marker='+',s=40)
ax.scatter(x, y, z1,c='b',marker='*',s=100)
ax.set(xlabel="X", ylabel="Y", zlabel="Z")
plt.show()
# 另一种
fig = plt.figure()
ax = Axes3D(fig)
ax.set_title('3d_image_show',fontsize=20)
ax.scatter(x, y, z,c='r',marker='+',s=40)
ax.scatter(x, y, z1,c='b',marker='*',s=100)
ax.set(xlabel="X", ylabel="Y", zlabel="Z")
plt.show()
# 快速
ax=plt.subplot(projection='3d')
ax.set_title('3d_image_show',fontsize=20)
ax.scatter(x, y, z,c='r',marker='+',s=40)
ax.scatter(x, y, z1,c='b',marker='*',s=100)
ax.set(xlabel="X", ylabel="Y", zlabel="Z")
plt.show()