MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / add_gridspec

Method add_gridspec

lib/matplotlib/figure.py:1564–1609  ·  view source on GitHub ↗

Low-level API for creating a `.GridSpec` that has this figure as a parent. This is a low-level API, allowing you to create a gridspec and subsequently add subplots based on the gridspec. Most users do not need that freedom and should use the higher-level methods

(self, nrows=1, ncols=1, **kwargs)

Source from the content-addressed store, hash-verified

1562 self.align_ylabels(axs=axs)
1563
1564 def add_gridspec(self, nrows=1, ncols=1, **kwargs):
1565 """
1566 Low-level API for creating a `.GridSpec` that has this figure as a parent.
1567
1568 This is a low-level API, allowing you to create a gridspec and
1569 subsequently add subplots based on the gridspec. Most users do
1570 not need that freedom and should use the higher-level methods
1571 `~.Figure.subplots` or `~.Figure.subplot_mosaic`.
1572
1573 Parameters
1574 ----------
1575 nrows : int, default: 1
1576 Number of rows in grid.
1577
1578 ncols : int, default: 1
1579 Number of columns in grid.
1580
1581 Returns
1582 -------
1583 `.GridSpec`
1584
1585 Other Parameters
1586 ----------------
1587 **kwargs
1588 Keyword arguments are passed to `.GridSpec`.
1589
1590 See Also
1591 --------
1592 matplotlib.pyplot.subplots
1593
1594 Examples
1595 --------
1596 Adding a subplot that spans two rows::
1597
1598 fig = plt.figure()
1599 gs = fig.add_gridspec(2, 2)
1600 ax1 = fig.add_subplot(gs[0, 0])
1601 ax2 = fig.add_subplot(gs[1, 0])
1602 # spans two rows:
1603 ax3 = fig.add_subplot(gs[:, 1])
1604
1605 """
1606
1607 _ = kwargs.pop('figure', None) # pop in case user has added this...
1608 gs = GridSpec(nrows=nrows, ncols=ncols, figure=self, **kwargs)
1609 return gs
1610
1611 def subfigures(self, nrows=1, ncols=1, squeeze=True,
1612 wspace=None, hspace=None,

Callers 15

subplotsMethod · 0.95
subplot_mosaicMethod · 0.95
test_label_outer_spanFunction · 0.80
test_remove_from_figureFunction · 0.80
test_constrained_layout6Function · 0.80
test_gridspec_addressingFunction · 0.80
test_submerged_subfigFunction · 0.80
test_savefig_transparentFunction · 0.80
test_figure_clearFunction · 0.80

Calls 2

GridSpecClass · 0.90
popMethod · 0.45

Tested by 15

test_label_outer_spanFunction · 0.64
test_remove_from_figureFunction · 0.64
test_constrained_layout6Function · 0.64
test_gridspec_addressingFunction · 0.64
test_submerged_subfigFunction · 0.64
test_savefig_transparentFunction · 0.64
test_figure_clearFunction · 0.64
test_basicMethod · 0.64
test_all_nestedMethod · 0.64