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

Function make_axes_gridspec

lib/matplotlib/colorbar.py:1497–1585  ·  view source on GitHub ↗

Create an `~.axes.Axes` suitable for a colorbar. The Axes is placed in the figure of the *parent* Axes, by resizing and repositioning *parent*. This function is similar to `.make_axes` and mostly compatible with it. Primary differences are - `.make_axes_gridspec` requires

(parent, *, location=None, orientation=None,
                       fraction=0.15, shrink=1.0, aspect=20, **kwargs)

Source from the content-addressed store, hash-verified

1495
1496@_docstring.interpd
1497def make_axes_gridspec(parent, *, location=None, orientation=None,
1498 fraction=0.15, shrink=1.0, aspect=20, **kwargs):
1499 """
1500 Create an `~.axes.Axes` suitable for a colorbar.
1501
1502 The Axes is placed in the figure of the *parent* Axes, by resizing and
1503 repositioning *parent*.
1504
1505 This function is similar to `.make_axes` and mostly compatible with it.
1506 Primary differences are
1507
1508 - `.make_axes_gridspec` requires the *parent* to have a subplotspec.
1509 - `.make_axes` positions the Axes in figure coordinates;
1510 `.make_axes_gridspec` positions it using a subplotspec.
1511 - `.make_axes` updates the position of the parent. `.make_axes_gridspec`
1512 replaces the parent gridspec with a new one.
1513
1514 Parameters
1515 ----------
1516 parent : `~matplotlib.axes.Axes`
1517 The Axes to use as parent for placing the colorbar.
1518 %(_make_axes_kw_doc)s
1519
1520 Returns
1521 -------
1522 cax : `~matplotlib.axes.Axes`
1523 The child Axes.
1524 kwargs : dict
1525 The reduced keyword dictionary to be passed when creating the colorbar
1526 instance.
1527 """
1528
1529 loc_settings = _normalize_location_orientation(location, orientation)
1530 kwargs['orientation'] = loc_settings['orientation']
1531 location = kwargs['ticklocation'] = loc_settings['location']
1532
1533 aspect0 = aspect
1534 anchor = kwargs.pop('anchor', loc_settings['anchor'])
1535 panchor = kwargs.pop('panchor', loc_settings['panchor'])
1536 pad = kwargs.pop('pad', loc_settings["pad"])
1537 wh_space = 2 * pad / (1 - pad)
1538
1539 if location in ('left', 'right'):
1540 gs = parent.get_subplotspec().subgridspec(
1541 3, 2, wspace=wh_space, hspace=0,
1542 height_ratios=[(1-anchor[1])*(1-shrink), shrink, anchor[1]*(1-shrink)])
1543 if location == 'left':
1544 gs.set_width_ratios([fraction, 1 - fraction - pad])
1545 ss_main = gs[:, 1]
1546 ss_cb = gs[1, 0]
1547 else:
1548 gs.set_width_ratios([1 - fraction - pad, fraction])
1549 ss_main = gs[:, 0]
1550 ss_cb = gs[1, 1]
1551 else:
1552 gs = parent.get_subplotspec().subgridspec(
1553 2, 3, hspace=wh_space, wspace=0,
1554 width_ratios=[anchor[0]*(1-shrink), shrink, (1-anchor[0])*(1-shrink)])

Callers

nothing calls this directly

Calls 12

subgridspecMethod · 0.80
set_width_ratiosMethod · 0.80
set_height_ratiosMethod · 0.80
add_subplotMethod · 0.80
popMethod · 0.45
get_subplotspecMethod · 0.45
set_subplotspecMethod · 0.45
set_anchorMethod · 0.45
get_figureMethod · 0.45
set_box_aspectMethod · 0.45
set_aspectMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…