1. add_subplot()函数

1.1 函数功能

Add an Axes to the figure as part of a subplot arrangement.

在画布中增加轴域

1.2 函数语法:

add_subplot(nrows, ncols, index, **kwargs)

1.3 函数参数

1.3.1 nrows, ncols, index

子图的位置由以下三个参数决定:

Three integers (nrows, ncols, index).
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.
index can also be a two-tuple specifying the (first, last) indices (1-based, and including last) of the subplot,
e.g., fig.add_subplot(3, 1, (1, 2)) makes a subplot that spans the upper 2/3 of the figure.

参数nrows与ncols决定画布被划分为nrows*ncols几部分。索引index从左上角开始,向右边递增。
索引也可以指定为二元数组,表示图表占据位置为:从索引的第1个参数到第2个参数的位置。
例如: fig.add_subplot(3, 1, (1, 2)),表示子图占据的位置为将画布三等分后的前两份位置。

import matplotlib.pyplot as plt
import numpy as npx1 = np.linspace(-2 * np.pi, 2 * np.pi, 500)
y1 = np.sin(x1)plt.subplot(1, 3, 1)
plt.plot(x1, y1)plt.show()

import matplotlib.pyplot as plt
import numpy as npx1 = np.linspace(-2 * np.pi, 2 * np.pi, 500)
y1 = np.sin(x1)plt.subplot(1, 3, (1,2))
plt.plot(x1, y1)plt.show()

1.3.2 projection

projection{None, 'aitoff', 'hammer', 'lambert', 'mollweide', 'polar',
'rectilinear', str}, optional

可选参数。当取值为polar表示绘制极线图。


import matplotlib.pyplot as plt
import numpy as npx1 = np.linspace(-2 * np.pi, 2 * np.pi, 500)
y1 = np.sin(x1)plt.subplot(1, 3, (1,2), projection='polar')
plt.plot(x1, y1)plt.show()

1.3.3 polar

polar  bool, default: False
If True, equivalent to projection='polar'.

布尔值类型,默认取值为:FALSE。当取值为True,相当于projection=‘polar’

import matplotlib.pyplot as plt
import numpy as npx1 = np.linspace(-2 * np.pi, 2 * np.pi, 500)
y1 = np.sin(x1)plt.subplot(1, 3, (1, 2), polar=True)
plt.plot(x1, y1)plt.show()

2. add_subplot 与subplot

目前理解到的为:

  1. subplot方法属于API绘图,而add_subplot方法为面向对象绘图
  2. 使用subplot方法自动生产画布与轴域,而add_subplot方法需要先添加画布figure,再在画布上添加轴域,add_subplot返回的即为子图的轴域
  3. 当绘制的子图之间出现遮挡,subplot方法会绘制代码位置靠后的图形,而add_subplot则会绘制所有图形,只是出现遮挡。
import matplotlib.pyplot as plt
import numpy as npx1 = np.linspace(-2 * np.pi, 2 * np.pi, 500)
y1 = np.sin(x1)
x2 = np.arange(-3, 3.5, 0.5)
y2 = np.power(x2, 2)plt.subplot(1, 3, (1, 2))
plt.plot(x1, y1)plt.subplot(2, 2, 3)
plt.scatter(x2, y2)plt.show()

import matplotlib.pyplot as plt
import numpy as npfig = plt.figure('add_subplot')x1 = np.linspace(-2 * np.pi, 2 * np.pi, 500)
y1 = np.sin(x1)
x2 = np.arange(-3, 3.5, 0.5)
y2 = np.power(x2, 2)sw1 = fig.add_subplot(1, 3, (1, 2))
sw1.plot(x1, y1)sw2 = fig.add_subplot(2, 2, 3)
sw2.scatter(x2, y2, s=20, facecolor='y')plt.show()

参考网站:https://matplotlib.org/stable/api/figure_api.html#matplotlib.figure.Figure.add_subplot

add_subplot()--matplotlib相关推荐

  1. python matplotlib.figure.Figure.add_subplot()方法的使用

    官方文档 https://matplotlib.org/api/_as_gen/matplotlib.figure.Figure.html?highlight=add_subplot#matplotl ...

  2. python实验六 语音信号处理

    目录 实验目的: 实验原理: 实验准备: 实验步骤与内容: 参考代码: 实验目的: 依托语音信号处理领域的声学特征提取任务,学习常用的语音信号处理工具,实现对语音数据的预处理和常用特征提取等操作: 熟 ...

  3. matplotlib.pyplot中add_subplot方法参数的含义

    有代码如下: import matplotlib.pyplot as plt from numpy import *x = [1, 2, 3, 4, 5] y = [1, 4, 9, 16, 20] ...

  4. pycharm matplotlib.pyplot.figure().add_subplot()绘制三维图时报错:ValueError: Unknown projection 3d(bug)

    报错描述 出于安全考虑,CSDN不让文章标题使用英文单引号 ValueError: Unknown projection '3d' # -*- coding: utf-8 -*- "&quo ...

  5. python matplotlib:figure,add_subplot,subplot,subplots讲解实现

    最近又用到了matplotlib 中画图的函数.总结几个常用的函数的作用于区别. from matplotlib import pyplot as plt 1.figure() 函数定义matplot ...

  6. python matplotlib fig = plt.figure() fig.add_subplot()

    一.matplotlib.pyplot.figure() Create a new figure, or activate an existing figure. matplotlib官网 功能: 创 ...

  7. matplotlib.pyplot中add_subplot方法参数111的含义

    >引自:http://www.codeweblog.com/matplotlib-pyplot中add_subplot方法参数111的含义/

  8. python matplotlib.pyplot中add_subplot subplot函数的用法与区别(其实没什么区别)

    引用文章 https://blog.csdn.net/you_are_my_dream/article/details/53439518

  9. Python关于%matplotlib inline

    我在做一个比赛需要使用到LSTM模型对时间序列进行预测,然后在github代码中经常会看到这样的代码: import numpy import matplotlib.pyplot as plt fro ...

  10. matlab plot不均匀间隔,matplotlib如何绘制间隔为2^n的不均匀图形?

    如果我的意见不够清楚,请你问.:)from matplotlib import pyplot as plt # Instanciating my lists... f = lambda x:x**2 ...

最新文章

  1. 分布式一致性(共识)算法(Paxos,raft,ZAB)的一些总结
  2. 信息安全系统设计基础第五周学习总结
  3. 普通话计算机考试相关信息,普通话考试常见问题有哪些
  4. 基于TensorFlow Serving的深度学习在线预估
  5. [会议分享]2020全球软件大会分享-PWA在项目中的最佳实践
  6. 平时的鸿星尔克VS开挂后的鸿星尔克
  7. Rwordseg安装
  8. python爬取新闻发送微信_如何利用 Python 爬虫实现给微信群发新闻早报?(详细)...
  9. python 30个小代码_30个Python常用极简代码,拿走就用
  10. margin-left:10px; 不同浏览器距离为什么不一样?
  11. “Ceph浅析”系列之二——Ceph概况
  12. matlab进行道格拉斯筛选,柯布-道格拉斯(Cobb-Douglas)生产函数模型.doc
  13. 新浪微博单点登陆分析
  14. 使用VMware虚拟机搭建爱快路由器PPPoE服务器环境
  15. 后缀自动机入门/基本概念
  16. HDU 5250 三阶魔方(模拟、置换)
  17. 首次跌至发行价的Snap,要如何抵抗社交巨头Facebook的抄袭?
  18. 传奇服务器最多登录人数设置,传奇服务器中如何设置角色升级经验值数量
  19. Tiptop开发工具 Genero Studio 2.40.11软件汉化包
  20. PDF如何合并为一个PDF?

热门文章

  1. Atitit s2018 s3 doc list alldvc.docx .docx s2018 s3f doc compc s2018 s3f doc homepc sum doc dvcCom
  2. Atitit 艺术与编程艺术 项目工程艺术 1. 艺术可以分为造型艺术、表演艺术、综合艺术和语言艺术四大类。 1 2. 造型艺术 10 2 2.1. (一) 绘画和雕塑  11 2 2.2. (二
  3. Atititi atiitt eam pam资产管理 购物表去年.xlsx
  4. Atitit.软件开发的三层结构isv金字塔模型
  5. paip.c++ qt 共享库dll的建立
  6. 从不同视角理解第三方支付
  7. 如何对国内股票的名称进行脱敏(待续)
  8. (转)比特币有了定价模型?过去四年94%的价格波动可由此解释
  9. Julia : array[ ] 与几种过滤条件
  10. (转)专访Palantir创始人:如何接二连三创出独角兽公司?