Python学习(2):绘制子图

效果如下:
在这里插入图片描述
代码如下

import matplotlib.pyplot as plt

fig1 = plt.figure(num=4, figsize=(10, 10),dpi=80)
#使用add_subplot在窗口加子图
#三个参数分别为:行数,列数,本子图是所有子图中的第几个,最后一个参数设置错了子图可能发生重叠
ax11 = fig1.add_subplot(2,2,1)  
ax12 = fig1.add_subplot(2,2,2)
ax13 = fig1.add_subplot(2,2,3)
ax14 = fig1.add_subplot(2,2,4)
#绘制曲线 
ax11.plot(time1,v,color='b')
ax11.set_xlabel('时间(s)')
ax11.set_ylabel('速度(m/s)')
ax11.set_title('速度')

ax12.plot(time1,a,color='b')
ax12.set_xlabel('时间(s)')
ax12.set_ylabel('加速度(m/s^2)')
ax12.set_title('加速度')

ax13.plot(time1,x,color='b')
ax13.set_xlabel('时间(s)')
ax13.set_ylabel('位移(m)')
ax13.set_title('位移')

ax14.plot(time1,h,color='b')
ax14.set_xlabel('时间(s)')
ax14.set_ylabel('间距(m)')
ax14.set_title('间距')

plt.suptitle('总标题',fontsize=36)   #添加总标题
plt.savefig('./fig1.png')   #将生成的图片保存
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值