print(help(plt.subplots))

subplots(nrows=1, ncols=1, sharex=False, sharey=False, squeeze=True, subplot_kw=None, gridspec_kw=None, **fig_kw)
Create a figure and a set of subplots

This utility wrapper makes it convenient to create common layouts of
subplots, including the enclosing figure object, in a single call.

Parameters
----------
nrows, ncols : int, optional, default: 1
    Number of rows/columns of the subplot grid.

sharex, sharey : bool or {'none', 'all', 'row', 'col'}, default: False
    Controls sharing of properties among x (`sharex`) or y (`sharey`)
    axes:

        - True or 'all': x- or y-axis will be shared among all
          subplots.
        - False or 'none': each subplot x- or y-axis will be
          independent.
        - 'row': each subplot row will share an x- or y-axis.
        - 'col': each subplot column will share an x- or y-axis.

    When subplots have a shared x-axis along a column, only the x tick
    labels of the bottom subplot are created. Similarly, when subplots
    have a shared y-axis along a row, only the y tick labels of the first
    column subplot are created. To later turn other subplots' ticklabels
    on, use :meth:`~matplotlib.axes.Axes.tick_params`.

squeeze : bool, optional, default: True
    - If True, extra dimensions are squeezed out from the returned
      array of Axes:

        - if only one subplot is constructed (nrows=ncols=1), the
          resulting single Axes object is returned as a scalar.
        - for Nx1 or 1xM subplots, the returned object is a 1D numpy
          object array of Axes objects.
        - for NxM, subplots with N>1 and M>1 are returned as a 2D array.

    - If False, no squeezing at all is done: the returned Axes object is
      always a 2D array containing Axes instances, even if it ends up
      being 1x1.

subplot_kw : dict, optional
    Dict with keywords passed to the
    :meth:`~matplotlib.figure.Figure.add_subplot` call used to create each
    subplot.

gridspec_kw : dict, optional
    Dict with keywords passed to the
    :class:`~matplotlib.gridspec.GridSpec` constructor used to create the
    grid the subplots are placed on.

**fig_kw :
    All additional keyword arguments are passed to the :func:`figure` call.

Returns
-------
fig : :class:`matplotlib.figure.Figure` object

ax : Axes object or array of Axes objects.

    ax can be either a single :class:`matplotlib.axes.Axes` object or an
    array of Axes objects if more than one subplot was created.  The
    dimensions of the resulting array can be controlled with the squeeze
    keyword, see above.

Examples
--------
First create some toy data:

>>> x = np.linspace(0, 2*np.pi, 400)
>>> y = np.sin(x**2)

Creates just a figure and only one subplot

>>> fig, ax = plt.subplots()
>>> ax.plot(x, y)
>>> ax.set_title('Simple plot')

Creates two subplots and unpacks the output array immediately

>>> f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
>>> ax1.plot(x, y)
>>> ax1.set_title('Sharing Y axis')
>>> ax2.scatter(x, y)

Creates four polar axes, and accesses them through the returned array

>>> fig, axes = plt.subplots(2, 2, subplot_kw=dict(polar=True))
>>> axes[0, 0].plot(x, y)
>>> axes[1, 1].scatter(x, y)

Share a X axis with each column of subplots

>>> plt.subplots(2, 2, sharex='col')

Share a Y axis with each row of subplots

>>> plt.subplots(2, 2, sharey='row')

Share both X and Y axes with all subplots

>>> plt.subplots(2, 2, sharex='all', sharey='all')

Note that this is the same as

>>> plt.subplots(2, 2, sharex=True, sharey=True)

翻译:
例子
--------
首先创建一些玩具数据:

>>> x = np.linspace(0,2 * np.pi,400)
>>> y = np.sin(x ** 2)

只创建一个数字,只创建一个子图

>>> fig,ax = plt.subplots()
>>> ax.plot(x,y)
>>> ax.set_title('简单情节')

创建两个子图并立即解压缩输出数组

>>> f,(ax1,ax2)= plt.subplots(1,2,sharey = True)
>>> ax1.plot(x,y)
>>> ax1.set_title('共享Y轴')
>>> ax2.scatter(x,y)

创建四个极轴,并通过返回的数组访问它们

>>> fig,axes = plt.subplots(2,2,subplot_kw = dict(polar = True))
>>> axes [0,0] .plot(x,y)
>>>轴[1,1] .scatter(x,y)

与每列子图共享一个X轴

>>> plt.subplots(2,2,sharex ='col')

与每行子图共享Y轴

>>> plt.subplots(2,2,sharey ='row')

与所有子图共享X轴和Y轴

>>> plt.subplots(2,2,sharex ='all',sharey ='all')

请注意,这与

>>> plt.subplots(2,2,sharex = True,sharey = True)相似
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值