利用matplotlib在python上绘制3D散点图

参考官方演示文档

首先,需要导入第三包:

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

然后绘图:

ax = plt.figure().add_subplot(111, projection = '3d')
#基于ax变量绘制三维图
#xs表示x方向的变量
#ys表示y方向的变量
#zs表示z方向的变量,这三个方向上的变量都可以用list的形式表示
#m表示点的形式,o是圆形的点,^是三角形(marker)
#c表示颜色(color for short)
ax.scatter(xs, ys, zs, c = 'r', marker = '^') #点为红色三角形

#设置坐标轴
ax.set_xlabel('X Label')
ax.set_ylabel('Y Label')
ax.set_zlabel('Z Label')

#显示图像
plt.show()

注:

上面的

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

是下面代码的略写

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


评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值