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


相关推荐

  • SSH+activity工作流集成开发「建议收藏」

    SSH+activity工作流集成开发「建议收藏」一直没有更新最近,把以前的资料整理下。SSH的集成配置清查看上一篇struts-2.3.24+spring-framework-4.1.6.RELEASE+hibernate-release-4.3.10.Final集成开发导入activity工作流需要的jaractiviti-bpmn-converter-5.16.4.jaractiviti-bpmn-layout-5

    2022年5月18日
    41
  • Java实现hello world代码

    Java实现hello world代码publicclassHelloWorld {    publicstaticvoidmain(String[]args){       System.out.println("HelloWorld");    }}

    2022年5月28日
    44
  • iapp邮箱钓鱼源码制作_充值钓鱼网站源码

    iapp邮箱钓鱼源码制作_充值钓鱼网站源码文件名称:php下载收藏√[54321]开发工具:PHP文件大小:1715KB上传时间:2015-11-13下载次数:0提供者:fgg详细说明:最新qq钓鱼空间php源码需要修改数据库连接-Needtomodifytheconnection文件列表(点击判断是否您需要的文件,如果是垃圾请在下面评价投诉):最新空间php源码\test\1.s…

    2022年8月24日
    5
  • Ubuntu安装显卡驱动教程

    Ubuntu安装显卡驱动教程一 参考资料环境搭建 01 Ubuntu16 04 如何查看显卡信息及安装 NVDIA 显卡驱动二 环境配置系统 Ubuntu16 04 显卡 NVIDIAGeForc 4GB 三 准备工作 1 根据电脑显卡型号 下载对应显卡驱动下载链接 博主对应下载的驱动版本 NVIDIA Linux x86 64 470 57 02 run2 将显卡驱动放到 home yichao Downloads 目录四 关键步骤 1 查看显卡型号 驱动 查看显卡型号 ubuntu

    2025年6月17日
    3
  • 检测计算机命令,磁盘检测命令chkdsk的使用方法

    检测计算机命令,磁盘检测命令chkdsk的使用方法经常看到有很多朋友在系统开机的时候因系统自检程序时间过长而往往直接跳过磁盘检测 而直接跳过这种心急的想法有时候会引来大祸患 今天我们介绍的 chkdsk 命令是系统自带的系统修复命令 可以帮助我们解决很多常见问题 它可以帮助恢复系统文件 有时可以延缓硬盘的寿命 对此想要有了解的朋友跟随小编一起来看看吧 磁盘检测的原因多是由于系统检测到磁盘数据调用错误或者数据文件丢失而自发引起的一种自我保护措施 使用磁

    2025年6月19日
    3
  • dedecms 封面模板和列表模板有什么不同

    dedecms 封面模板和列表模板有什么不同

    2021年9月22日
    61

发表回复

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

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