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


相关推荐

  • 华为 eNSP 模拟器安装教程(内含下载地址)[通俗易懂]

    华为 eNSP 模拟器安装教程(内含下载地址)[通俗易懂]本文指导大家在Windows操作系统上完成华为eNSP模拟器的安装

    2022年10月9日
  • IDEA203版本激活码_通用破解码

    IDEA203版本激活码_通用破解码,https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
  • android sdk安装过程,图文详解Android 3.0 SDK安装教程

    android sdk安装过程,图文详解Android 3.0 SDK安装教程【51CTO编者按】我们已经为喜欢Android3.0的朋友提供Android3.0SDK下载,本文我们将向大家介绍Android3.0SDK安装教程,本教程与玩模拟器需要比较好的电脑配置,建议至少要i系列CPU,即使如此还是会经常卡,只建议给那些想尝鲜的和只想玩系统的朋友。一、准备阶段:1.安装JavaJDK2.进入“控制面板”-“系统”-“高级系统设置”在弹出的窗口中,选择“环境…

    2022年7月21日
  • 我国无线2.4g及5g信道-个人笔记

    我国无线2.4g及5g信道-个人笔记中国无线信道规划2.4G频段(2.412GHZ-2.472GHZ)信道中心频率频率范围01   2412  2401-242302   2417  2406-242803   2422  2411-243304   2427  2416-243805   2432  2421-244306   2437  2426-244807   2442  2431-245308   2447  2426-244809   2452  2441-246310   2457  24

    2022年6月1日
  • 路径不正确的文件怎么删除(文件不存在)

    打开记事本输入:DEL/F/A/Q\?\%1RD/S/Q\?\%1保存为删除.bat将要删除的文件夹或文件拖到删除图标上,世界清净了。

    2022年4月12日
  • 区块链对传播格局_博弈论66个经典例子

    区块链对传播格局_博弈论66个经典例子一、区块链数据结构与算法首先,讲一下区块链基本的技术内容。区块链,本质是由两个部分构成:第一部分是数据结构,第二部分是算法。这两部分是可以分割的,也最好分割开来看。首先看区块链的数据结构,其实非常简单:它是由很多的区块组成的,每个块都包括很多的数据,主要是交易数据。区块互相之间的链接就是通过hash过程,也就说我们把前一块的内容hash成一个数字签名,然后放在后一块里面,形成一个链…

    2022年8月31日

发表回复

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

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