Python plt 利用subplot 实现在一张画布同时画多张图
作者:HJC256ZY 时间:2021-02-04 02:50:17
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);
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。如有错误或未考虑完全的地方,望不吝赐教。
来源:https://blog.csdn.net/HJC256ZY/article/details/106725917
标签:Python,plt,subplot,画多图
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
asp如何用OdbcRegTool组件来创建一个数据源?
2010-06-12 12:55:00
PyCharm常用配置和常用插件(小结)
2023-07-21 03:21:17
![](https://img.aspxhome.com/file/2023/7/63617_0s.png)
Php中文件下载功能实现超详细流程分析
2023-10-07 17:09:13
![](https://img.aspxhome.com/file/2023/2/55762_0s.png)
MySQL中两种快速创建空表的方式的区别
2008-12-17 14:34:00
ASP中使用存储过程介绍
2008-10-10 12:10:00
10个最容易犯的HTML标签错误
2010-09-13 12:37:00
![](https://img.aspxhome.com/file/UploadPic/20109/13/01-23s.jpg)
Python读取二进制文件代码方法解析
2023-06-14 14:32:35
JavaScript中的"类" 序言
2008-02-18 13:26:00
原生js实现瀑布流效果
2023-09-04 07:11:02
Python selenium 三种等待方式解读
2023-12-26 05:37:56
ASP小偷(远程数据获取)程序的入门教程
2007-09-21 12:48:00
python pygame实现五子棋小游戏
2021-10-31 13:39:23
django 在原有表格添加或删除字段的实例
2023-11-25 04:21:08
python实现五子棋游戏(pygame版)
2021-09-15 16:01:42
![](https://img.aspxhome.com/file/2023/6/65916_0s.gif)
php 保留小数点
2023-06-21 10:47:04
使用Spry轻松将XML数据显示到HTML页
2007-11-16 16:44:00
![](https://img.aspxhome.com/file/UploadPic/200711/16/2007111616510974s.jpg)
解决Python安装时报缺少DLL问题【两种解决方法】
2023-12-27 01:49:12
![](https://img.aspxhome.com/file/2023/3/66923_0s.jpg)
ASP无组件上载,带进度条,多文件上载
2008-10-29 10:03:00
JS中实现JAVA的hashCode算法
2008-08-03 17:00:00
Request.ServerVariables应用实例
2008-03-11 11:57:00