美文网首页
2020-05-28

2020-05-28

作者: 小东0818 | 来源:发表于2020-05-28 17:02 被阅读0次

plt.subplot()

plt.subplot(nrows, ncols, index, **kwargs)

第一个参数:*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。

第二个参数: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就是一个线形图。

第三个参数: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()可以依次画出这些子图,优点是简单明了,缺点是略显麻烦。

————————————————

版权声明:本文为CSDN博主「我是小蚂蚁」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/missyougoon/article/details/90543210

相关文章

  • 女孩子一定要知道的事

    女孩子一定要知道 大大写作家 关注 1.282 · 字数 295 · 阅读 226 2020-05-28 22:5...

  • 2020-05-28

    2020-05-28 昨天听说要对各类研究数据给客户汇报,领导帮我梳理了一遍,可是自己还是没有底,今天早上再次和领...

  • 心平气和/心中的小天地

    2020-05-28 只要想做成,定下心,“一切都往那边走”。 就是可以做到的! 都是自己在做选择。 相信自己就是...

  • 马上六岁啦

    2020-05-28 昨天晚上我在整理衣服,枝宝跑过来贴着穿衣镜各种挤眉弄眼,完了忽然对我说:“妈妈,我真是个天才...

  • 【099】2020-05-28

    01 这个2020-05-28数字有天机?那为何钟爱? 今天看了这个数字,莫名心中充喜,好久没有这个名状啦,什么是...

  • 2020-11-01

    情景剧策划方案最新2020策划方案汇总 学习啦 思欣 2020-05-28 09:29:28 情景剧通常有一个封...

  • 论葡京的倒掉

    写于2020-05-28 听说,澳门葡京的支柱倒掉了,听说而已,我没有亲见。但我却读过支柱未倒时的新闻,被称为“爱...

  • 周记

    2020-05-28 不纠结于境遇,在不同的境遇里做好自己的事情,不忘初心。 不同角度看问题是不同的。而看问题不应...

  • 2020-05-29

    2020-05-28 成长日志第343天 家名:温暖有爱之家 家规:真诚待人不自欺,学会看见懂得感恩,正面如是的表...

  • 家有四宝!龙凤成长记之第18天

    2020-05-28 1. 儿子练了大提琴,又去上大提琴课,老师夸他震音进步了很多!早上跟爸爸出去吃早餐,晚上又跟...

网友评论

      本文标题:2020-05-28

      本文链接:https://www.haomeiwen.com/subject/gemaahtx.html