plt.subplot()函数中网格grid的理解

本文详细解析了matplotlib库中plt.subplot()函数的使用,包括三种参数设置方式:nrows, ncols, index;pos参数;以及grid的概念。通过实例说明了如何在网格中定位子图,并展示了如何为特定子图添加颜色,为后续在子图上进行图像可视化提供了基础。" 109550246,10036474,ES6中的类与缓存优化,"['JavaScript', 'ES6语法', '缓存策略', '编程实践']
摘要由CSDN通过智能技术生成

传送门
该函数的三种写法:
subplot(nrows, ncols, index, **kwargs)
subplot(pos, **kwargs)
subplot(ax)
一开始一直没搞明白subplot(子图)和index(索引)的关系,搞懂这个等于知道了该函数的用法了。
先看官方文档解释:
*args
Either a 3-digit integer or three separate integers describing the position of the subplot. If the three integers are nrows, ncols, and index in order, the subplot will take the index position on a grid with nrows rows and ncols columns. index starts at 1 in the upper left corner and increases to the right.
pos is a three digit integer, where the first digit is the number of rows, the second the number of columns, and the third the index of the subplot. i.e. fig.add_subplot(235) is the same as fig.add_subplot(2, 3, 5). Note that all integers must be less than 10 for this form to work.
所谓的grid翻译过来的意思就是网格
例如要画一个4行5列的网格,index表示就是网格的索引号,从1从左到右,从上至下,索引号分别如下:
网格及索引
现在假如要把小网格添加颜色,如把1,7,13,19,15染成红色,代码如下:

for i in [
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值