matplotlib.pyplot.subplots()的参数解析

subplots(nrows=1, ncols=1, *, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None)
所有参数如下:
nrows,ncols:
|参数类型:int, default: 1(default:1 默认为1)
|功能:nrows行数,ncols列数
|例:fig, axes = plt.subplots(nrows=2, ncols=3)
画布即为2行3列
在这里插入图片描述
sharex,sharey:
|参数类型:bool or {‘none’, ‘all’, ‘row’, ‘col’}, default: False
|功能:控制子图之间x轴(sharex)或y轴(sharey)是否共享
||True or ‘all’: 所有子图共享x轴或y轴

||False or ‘none’: 每一个子图的x轴或y轴都是独立的

||‘row’: 每行子图的x轴或y轴都是共享的.

||‘col’: 每列子图的x轴或y轴都是共享的.

|例:

import matplotlib.pyplot as plt

squares = [i for i in range(10)]
squares2 = [i for i in range(5)]
squares3 = [i * i for i in range(5)]

fig, axes = plt.subplots(nrows=2, ncols=2, sharex='row')
axes[0, 0].plot(squares, squares, linewidth=3)
axes[0, 1].plot(squares2, squares3, linewidth=3)

使用sharex=‘row’之前
使用sharex=‘row’之后

squeeze:
|参数类型:bool, default: True
|功能:
||True:如果只创建了一个子图像,返回的坐标轴对象是一个标量
如果创建的是1xN单行或者MX1单列的子图像,返回坐标系对象是一个一维numpy数组
如果创建的是 NXM(N>1,M>1) 多行多列的子图像,返回坐标系对象是一个2维数组
||Flase:没有进行降维压缩,无论图像如何排列返回的坐标系对象总是2维数组的。
|例:

subplot_kw:
|参数类型:dict, optional
|功能:创建极坐标系
|例:fig, axs = plt.subplots(subplot_kw=dict(polar=True))
在这里插入图片描述

gridspec_kw:
|参数类型:dict, optional
|功能:自定义图形布局
|例:fig, axs = plt.subplots(3,3,gridspec_kw={'left': 0.05, 'right': 0.48, 'wspace': 0.05})
在这里插入图片描述

返回值:

  • 2
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值