matplotlib subplot绘制多个子图的方法示例
作者:繁小华 时间:2021-12-18 14:49:50
在matplotlib下,一个Figure对象可以包含多个子图(Axes),可以使用subplot()快速绘制,其调用形式如下:
subplot(numRows, numCols, plotNum)
图表的整个绘图区域被分成numRows行和numCols列,plotNum参数指定创建的Axes对象所在的区域,如何理解呢?
如果numRows = 3,numCols = 2,那整个绘制图表样式为3X2的图片区域,用坐标表示为(1,1),(1,2),(1,3),(2,1),(2,2),(2,3)。这时,当plotNum = 1时,表示的坐标为(1,3),即第一行第一列的子图;
import numpy as np
import matplotlib.pyplot as plt
# 分成2x2,占用第一个,即第一行第一列的子图
plt.subplot(221)
# 分成2x2,占用第二个,即第一行第二列的子图
plt.subplot(222)
# 分成2x1,占用第二个,即第二行
plt.subplot(212)
plt.show()
import matplotlib.pyplot as plt
import numpy as np
# plt.plot([1, 2, 3, 4], [1, 4, 9, 16], 'ro')
# plt.axis([0, 6, 0, 20])
# plt.show()
# t = np.arange(0., 5., 0.2)
# plt.plot(t, t, 'r--', t, t ** 2, 'bs', t, t ** 3, 'g^')
def f(t):
return np.exp(-t) * np.cos(2 * np.pi * t)
t1 = np.arange(0, 5, 0.1)
t2 = np.arange(0, 5, 0.02)
plt.figure(12)
plt.subplot(221)
plt.plot(t1, f(t1), 'bo', t2, f(t2), 'r--')
plt.subplot(222)
plt.plot(t2, np.cos(2 * np.pi * t2), 'r--')
plt.subplot(212)
plt.plot([1, 2, 3, 4], [1, 4, 9, 16])
plt.show()
来源:https://blog.csdn.net/sunshihua12829/article/details/52786144
标签:matplotlib,subplot,多子图
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
兼容所有浏览器的设为首页与显示小策略
2009-01-12 18:50:00
![](https://img.aspxhome.com/file/UploadPic/20091/12/make-y-home-page-firefox-57s.png)
Python 支持向量机分类器的实现
2021-05-13 01:54:57
Python中hash加密简介及使用方法
2022-08-16 01:06:06
python snownlp情感分析简易demo(分享)
2021-07-18 04:32:35
![](https://img.aspxhome.com/file/2023/0/72250_0s.jpg)
python里的条件语句和循环语句你了解多少
2022-07-19 02:27:49
![](https://img.aspxhome.com/file/2023/6/107616_0s.gif)
python 实现在txt指定行追加文本的方法
2021-09-08 22:14:40
pandas中的DataFrame数据遍历解读
2023-12-03 21:57:34
![](https://img.aspxhome.com/file/2023/7/93457_0s.png)
python单向链表的基本实现与使用方法【定义、遍历、添加、删除、查找等】
2021-08-24 03:26:17
Python使用Kubernetes API访问集群
2023-09-23 05:35:31
![](https://img.aspxhome.com/file/2023/9/69539_0s.png)
一文带你熟悉Go语言中函数的使用
2023-07-13 08:22:23
用Python画一个LinkinPark的logo代码实例
2022-09-27 05:52:19
![](https://img.aspxhome.com/file/2023/9/90339_0s.png)
FrontPage2002简明教程五:css样式表的应用
2008-09-17 11:31:00
![](https://img.aspxhome.com/file/UploadPic/200810/17/20081017113345609s.jpg)
ASP(JScript)构建SQL语句“类”
2008-04-30 07:12:00
Python3.7实现中控考勤机自动连接
2022-08-07 16:24:22
Python matplotlib学习笔记之坐标轴范围
2022-04-21 16:24:28
![](https://img.aspxhome.com/file/2023/8/88038_0s.jpg)
python关闭print输出信息详情
2023-06-21 17:21:09
python中创建一个包并引用使用的操作方法
2023-05-19 03:06:09
![](https://img.aspxhome.com/file/2023/2/115662_0s.png)
从HTTP状态 301,302,200 来看页面跳转
2007-09-26 13:46:00
js图片水平翻转后垂直翻反转的特效代码
2009-03-06 15:33:00
教你利用python实现企业微信发送消息
2023-09-06 11:20:55
![](https://img.aspxhome.com/file/2023/2/105052_0s.png)