Python plt 利用subplot 实现在一张画布同时画多张图
2021-02-26 20:29:29
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);
以上为个人经验,希望能给大家一个参考,也希望大家多多支持IT技术网。如有错误或未考虑完全的地方,望不吝赐教。
您可能感兴趣的文章:
- python实现在一个画布上画多个子图
- python使用matplotlib:subplot绘制多个子图的示例
- matplotlib绘制多个子图(subplot)的方法
相关阅读
- 用python对excel进行操作(读,写,修改)
- 使用Python实现音频双通道分离
- 通过python-pptx模块操作ppt文件的方法
- python Pexpect模块的使用
- python语言time库和datetime库基本使用详解
- Python新建项目自动添加介绍和utf-8编码的方法
- Python 可视化神器Plotly详解
- python中str内置函数用法总结
- python中温度单位转换的实例方法
- python函数超时自动退出的实操方法
- Python 利用argparse模块实现脚本命令行参数解析
- 一个非常简单好用的Python图形界面库(PysimpleGUI)
- python字典按照value排序方法
- python字典与json转换的方法总结
- python获取天气接口给指定微信好友发天气预报
- 详解python 条件语句和while循环的实例代码
- python Timer 类使用介绍
- Python+kivy BoxLayout布局示例代码详解