欢迎来到代码驿站!

Python代码

当前位置:首页 > 软件编程 > Python代码

Python plt 利用subplot 实现在一张画布同时画多张图

时间:2021-06-12 08:19:33|栏目:Python代码|点击:

subplot(arg1, arg2, arg3)

arg1: 在垂直方向同时画几张图

arg2: 在水平方向同时画几张图

arg3: 当前命令修改的是第几张图

plt.figure()另起一张新的画布
from PIL import Image
import matplotlib.pyplot as plt
image1 = Image.open('1.jpg')
image2 = Image.open('2.jpg')
plt.subplot(121) 
plt.imshow(image1)
plt.subplot(122) 
plt.imshow(image2)
plt.show() 

补充:matplotlib 同一个画布绘制多张图,主次刻度,竖线

我就废话不多说了,大家还是直接看代码吧~

import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
# 要分析的数据
profit = df_profit.groupby('release_year')['profit'].agg(['mean','sum','count'])
# 在同一个画布中绘制两张图
plt.figure(figsize=(15,15))
# 图一:每年上映电影的总收入
ax = plt.subplot(211)
# 设置x轴 范围
ax.set_xlim(1958,2018)
# 设置x轴 主刻度,(次刻度设置minor=True)
ax.set_xticks(np.arange(1960,2018,5), minor=False)
# 画图
ax.plot(profit['sum'], linestyle='--', marker='o', markersize=5)
ax.set_title('The Sum of Movies\' Revenue v.s. Release Year')
ax.set_ylabel('Revenue(USD)')
# 增加竖线
ax.axvline(x=1977, color='#d46061', linewidth=1);
# 图二:每年上映电影的平均收入
ax = plt.subplot(212)
# 设置x轴 范围
ax.set_xlim(1958,2018)
# 设置x轴 主刻度
ax.set_xticks(np.arange(1960,2018,5))
# 画图
ax.plot(profit['mean'], linestyle='--', marker='o', markersize=5);
ax.set_title('The Mean of Movies\' Revenue v.s. Release Year')
ax.set_xlabel('Release Year')
ax.set_ylabel('Revenue(USD)')
# 增加竖线
ax.axvline(x=1977, color='#d46061', linewidth=1);

上一篇:Python实用技巧之列表、字典、集合中根据条件筛选数据详解

栏    目:Python代码

下一篇:Python中for循环详解

本文标题:Python plt 利用subplot 实现在一张画布同时画多张图

本文地址:http://www.codeinn.net/misctech/140679.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有