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


相关推荐

  • 数据挖掘 韩家炜_数据挖掘的特点

    数据挖掘 韩家炜_数据挖掘的特点第三版25页  数据挖掘又称知识发现(KDD:KnowledgeDiscoveryinDatabase),即“从数据中挖掘知识”。  丰富的数据以及对强有力的数据分析工具的需求,这种情况被描述为“数据丰富,但信息匮乏”。数据挖掘可以看作信息技术自然进化的结果。数据库和数据管理产业在一些关键功能的开发上不断发展:数据收集和数据库创建数据管理(包括数据存储和检索、数据库事务处理)高级数

    2025年6月27日
    3
  • Python中sys模块

    sys-系统特定的参数和功能该模块提供对解释器使用或维护的一些变量的访问,以及与解释器强烈交互的函数。它始终可用。sys.argv传递给Python脚本的命令行参数列表。argv[0]是脚本名称(依赖于操作系统,无论这是否是完整路径名)。如果使用-c解释器的命令行选项执行命令,argv[0]则将其设置为字符串’-c’。如果没有脚本名称传递给Python解释器,argv[0]则为空字符串…

    2022年4月5日
    52
  • 地图API地址  百度地图开放平台

    地图API地址  百度地图开放平台

    2021年9月18日
    68
  • 虚拟存储管理_虚拟存储管理的基本条件

    虚拟存储管理_虚拟存储管理的基本条件必要性:前面的各种存储管理方式必须一次性全部装入内存才可以运行,直至作业运行结束才能释放全部内存资源,所以存在:(1)内存不满足作业地址空间要求时就不能运行(2)大量作业要求运行时只有少数作业装入内存运行,其他作业留在辅存等待程序执行呈现局部性特征,程序的执行局限于某个部分局限性⎧⎩⎨时间局限性{某条指令被执行,不久之后指令可能再次执行某条数据被访问,不久之后数据可能再次空间局限性…

    2022年9月26日
    3
  • java实现异步调用

    java实现异步调用1、使用线程池的逻辑实现异步调用packagecom.ourlang.dataextract.controller;importcom.google.common.util.concurrent.ThreadFactoryBuilder;importcom.ourlang.dataextract.common.CommonResult;importcom.ourlang.dataextract.service.ISInPatientListService;importorg.apach

    2022年7月11日
    19
  • python进阶(15)多线程与多进程效率测试「建议收藏」

    python进阶(15)多线程与多进程效率测试「建议收藏」前言在Python中,计算密集型任务适用于多进程,IO密集型任务适用于多线程正常来讲,多线程要比多进程效率更高,因为进程间的切换需要的资源和开销更大,而线程相对更小,但是我们使用的Python大多

    2022年8月7日
    5

发表回复

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

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