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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 基于OpenCv的人脸识别(Python完整代码)

    基于OpenCv的人脸识别(Python完整代码)目前人脸识别有很多较为成熟的方法,这里调用OpenCv库,而OpenCV又提供了三种人脸识别方法,分别是LBPH方法、EigenFishfaces方法、Fisherfaces方法。本文采用的是LBPH(LocalBinaryPatternsHistogram,局部二值模式直方图)方法。opencv是一个开源的的跨平台计算机视觉库,内部实现了图像处理和计算机视觉方面的很多通用算法,对于python而言,在引用opencv库的时候需要写为importcv2。其中,cv2是opencv的C++命名空间名称

    2022年6月7日
    51
  • Linux之常用命令

    Linux之常用命令2.常用命令2.1命令格式的说明命令格式:命令\[-选项][参数]参数eg:ls-la/usr说明:大部分命令遵从该格式多个选项时,可以一起写eg:ls–l–als–la简化选项与完整选项(注:并非所有选项都可使用完整选项)eg:ls–allls–a帮助命令:(相当于命令说明书)2.2帮助命令2.2.1man英文:…

    2022年5月28日
    35
  • Java 定时任务实现原理详解[通俗易懂]

    在jdk自带的库中,有两种技术可以实现定时任务。一种是使用Timer,另外一个则是ScheduledThreadPoolExecutor。下面为大家分析一下这两个技术的底层实现原理以及各自的优缺点。一、Timer1.Timer的使用classMyTaskextendsTimerTask{@Overridepublicvoidrun(){…

    2022年4月10日
    64
  • Databus 深入学习

    Databus 深入学习一、关于databusLinkedIn于2月26日开源了其低延时变化数据捕获系统Databus,该系统可以在MySQL以及Oracle数据源上捕获数据,当下LinkedIn只开源了Oracle上的连接器。Databus作为LinkedIn生态系统中的一致性保障组件,在低延时的情况下仍然具有高有效性;而其最大的特点莫过于无限制恢复能力及丰富的数据深度处理功能。二、基于da…

    2022年10月10日
    5
  • plsql oracle 使用教程

    plsql oracle 使用教程课程一PL/SQL基本查询与排序    本课重点:    1、写SELECT语句进行数据库查询    2、进行数学运算    3、处理空值    4、使用别名ALIASES    5、连接列    6、在SQLPLUS中编辑缓冲,修改SQLSCRIPTS    7、ORDERBY进行排序输出。  8、使用WHERE字段。    一…

    2022年6月3日
    51
  • \r,\n,\r\n的区别

    \r,\n,\r\n的区别

    2021年9月18日
    51

发表回复

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

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