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


相关推荐

  • 妈妈再也不用担心我的博客访问量了(一个可以刷博客访问量的小程序java)「建议收藏」

    妈妈再也不用担心我的博客访问量了(一个可以刷博客访问量的小程序java)「建议收藏」前言:相信很多写博客的朋友,会苦恼于博客访问量上不去的问题。博主最近工作比较新手动谢了个小程序,一个可以刷访问量的程序。当然主要是针对csdn博客。有了他就再也不必担心博客访问量上不去的问题了。注:博客最主要还是要自己做好seo优化,以及提高博客内容质量。本篇文章,仅供学习交流。大家如果有问题,可以留言。一,废话少说,看图:软件点击jar包直接运行:如下:稍后查看博客访问量会有变化哟,博主

    2022年6月17日
    20
  • VS2015序列号_autocad2008激活序列号

    VS2015序列号_autocad2008激活序列号
    VisualStudioTeamSystem2008TeamSuite(vs2008)正式中文版   
    VS2008简体中文正式版序列号大全
      
    1.VisualStudio2008ProfessionalEdition:
    XMQ2Y-4T3V6-XJ48Y-D3K2V-6C4WT
      
    2.VisualStudio2008TeamTestLoadAgent:
    WPX3J-BXC3W-BPYW

    2022年8月10日
    7
  • mybatiscodehelperpro激活码[最新免费获取]

    (mybatiscodehelperpro激活码)2021最新分享一个能用的的激活码出来,希望能帮到需要激活的朋友。目前这个是能用的,但是用的人多了之后也会失效,会不定时更新的,大家持续关注此网站~IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html…

    2022年3月26日
    405
  • SqlTransaction的解析

    SqlTransaction的解析SqlTransaction类表示要在SQLServer数据库中处理的Transact-SQL事务。无法继承此类应用程序通过在SqlConnection对象上调用BeginTransaction来创建SqlTransaction对象。对SqlTransactio

    2022年5月1日
    46
  • PLSQL注册码(永久可用)[通俗易懂]

    PLSQL注册码(永久可用)[通俗易懂]点击链接查看:http://note.youdao.com/noteshare?id=c2bdd7bf1e1478a2470267f58eada964&sub=10C22AEFB67B452CBAD539DA126DC821

    2022年7月13日
    35
  • Windows连接树莓派_树莓派4 win10专业版

    Windows连接树莓派_树莓派4 win10专业版一、准备工作树莓派3B+主板一个(系统已烧制完毕)win10电脑一台网线一条二、win10设置1.将网线与树莓派连接2.右击网络连接图标,选择打开“网络和Internet”设置3.打开网络和共享中心4.打开更改适配器设置5.选择以太网2,右击属性进入,对共享选项卡进行设置,勾选允许,并选择以太网三、查看树莓派IP通过快捷键win+R进入命令行界面…

    2022年10月14日
    1

发表回复

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

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