matplotlib画三维图


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()


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值