from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
# 设置图大小
fig = plt.figure(figsize=(16,9))
# 需要设置projection='3d 才会显示3D图
ax = fig.add_subplot(111, projection = '3d')
# 设置xyz轴坐标间隔
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.view_init(90,-90) #y,z
# 设置坐标轴刻度度量相等
ax.set_aspect('equal') # 2D图为 plt.gca().set_aspect('equal')
point1 = (0,0,0)
point2 = (1,1,1)
ax.scatter(point1[0], point1[1], point1[2],marker='*',c='r')
ax.scatter(point2[0], point2[1], point2[2],marker='^',c='b')
ax.plot((point1[0], point2[0]),(point1[1], point2[1]),(point1[2], point2[2]))
plt.show()
matplotlib画三维图
最新推荐文章于 2025-02-04 02:16:07 发布