传送门
该函数的三种写法:
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 [