plt.subplot()使用方法以及参数介绍

plt.subplot()使用方法以及参数介绍plt.subplot()plt.subplot(nrows,ncols,index,**kwargs)第一个参数:*args(官网文档描述)Eithera3-digitintegerorthreeseparateintegersdescribingthepositionofthesubplot.Ifthethreeintegersarenr…

大家好,又见面了,我是你们的朋友全栈君。

plt.subplot()

plt.subplot(nrows, ncols, index, **kwargs)

  1. 第一个参数:*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.
    可以使用三个整数,或者三个独立的整数来描述子图的位置信息。如果三个整数是行数、列数和索引值,子图将分布在行列的索引位置上。索引从1开始,从右上角增加到右下角。
    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.
    位置是由三个整型数值构成,第一个代表行数,第二个代表列数,第三个代表索引位置。举个列子:plt.subplot(2, 3, 5) 和 plt.subplot(235) 是一样一样的。需要注意的是所有的数字不能超过10。

  2. 第二个参数:projection : {None, ‘aitoff’, ‘hammer’, ‘lambert’, ‘mollweide’, ‘polar’, ‘rectilinear’, str}, optional
    The projection type of the subplot (Axes). str is the name of a costum projection, see projections. The default None results in a ‘rectilinear’ projection.
    可选参数:可以选择子图的类型,比如选择polar,就是一个极点图。默认是none就是一个线形图。

  3. 第三个参数:polar : boolean, optional
    If True, equivalent to projection=‘polar’. 如果选择true,就是一个极点图,上一个参数也能实现该功能。
    官方文档传送门:plt.subplot()

import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(1, 2, 2)
y1 = np.sin(x)

y2 = np.cos(x)

ax1 = plt.subplot(2, 2, 1, frameon = False) # 两行一列,位置是1的子图
plt.plot(x, y1, 'b--')
plt.ylabel('y1')
ax2 = plt.subplot(2, 2, 2, projection = 'polar')
plt.plot(x, y2, 'r--')
plt.ylabel('y2')
plt.xlabel('x')
plt.subplot(2, 2, 3, sharex = ax1, facecolor = 'red')
plt.plot(x, y2, 'r--')
plt.ylabel('y2')

plt.show()

以上代码画图如下:
在这里插入图片描述
可以看到plt.subplot()可以依次画出这些子图,优点是简单明了,缺点是略显麻烦。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/150508.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • mysql innodb与myisam存储文件的区别[通俗易懂]

    mysql innodb与myisam存储文件的区别

    2022年2月9日
    49
  • Kong网关介绍[通俗易懂]

    Kong网关介绍[通俗易懂]传统服务如下左图,通用函数重复使用在多个服务中,系统庞大僵化难以管理,由于会冲击其他服务导致的扩展困难,由于系统限制导致生产率低,如下右图是kong的解决方案kong特点:云原生:平台无关,kong可以在裸机和Kubernetes上运行。动态负载平衡:跨多个上游服务的流量负载均衡。…

    2025年10月24日
    6
  • flashfxp3.41中文版注册码:(适合最新版本)

    flashfxp3.41中文版注册码:(适合最新版本)推荐(尚未被封的Realkey)FLASHFXPvACq2ssbvAAAAAC1W7cJKQTzmx77zmqJICvA7d3WnUtWNXdrp8YuERRFdIvXfOPbcpABkVix2aRTgg6afcIKFPxS72XYljdE9tgQD/2r+kmfVBngGM4Qc9p7e0PcTfFF/1tt2bqlxS8r0L7z0jrqb5NSiPr…

    2022年7月26日
    5
  • 计算机网络的基本概念[通俗易懂]

    计算机网络的基本概念[通俗易懂]一:计算机网络的定义计算机网络的现代计算机技术与通信技术相互渗透,密切结合的产物,是随着社会对信息共享和信息传递的日益增强的需求而发展起来的,所谓计算机网络,就是利用通信设备和线路将地理位置不同的,

    2022年8月5日
    7
  • JMeter安装与接口测试入门[通俗易懂]

    JMeter安装与接口测试入门[通俗易懂]安装环境配置1、JDK版本:JDK1.8及以上;2、操作系统:JMeter可以在当前任何一个已经部署了Java的操作系统上运行,Unix(Solaris,Linux,etc)、Windows(98,NT,2000,XP,WIN7)、OpenVMSAlpha7.3+JDK安装与配置1、jdk安装:在官网下载jdk1.8版本压缩包,解压到指定文件夹即可。2、环境变量配置1)右键点击…

    2022年5月3日
    64
  • 数据库ER图基础概念整理

    数据库ER图基础概念整理什么是ER图?ER图即是实体关系图!ER图分为实体、属性、关系三个核心部分。实体是长方形体现,而属性则是椭圆形,关系为菱形。ER图中关联关系有三种:1对1(1:1):1对1关系是指对于实体集A与实体集B,A中的每一个实体至多与B中一个实体有关系;反之,在实体集B中的每个实体至多与实体集A中一个实体有关系。1对多(1:N):1对多关系是指实体集A与实体集B中至

    2022年6月21日
    25

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号