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

Function make_axes

lib/matplotlib/colorbar.py:1393–1493  ·  view source on GitHub ↗

Create an `~.axes.Axes` suitable for a colorbar. The Axes is placed in the figure of the *parents* Axes, by resizing and repositioning *parents*. Parameters ---------- parents : `~matplotlib.axes.Axes` or iterable or `numpy.ndarray` of `~.axes.Axes` The Axes to use

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

Source from the content-addressed store, hash-verified

1391
1392@_docstring.interpd
1393def make_axes(parents, location=None, orientation=None, fraction=0.15,
1394 shrink=1.0, aspect=20, **kwargs):
1395 """
1396 Create an `~.axes.Axes` suitable for a colorbar.
1397
1398 The Axes is placed in the figure of the *parents* Axes, by resizing and
1399 repositioning *parents*.
1400
1401 Parameters
1402 ----------
1403 parents : `~matplotlib.axes.Axes` or iterable or `numpy.ndarray` of `~.axes.Axes`
1404 The Axes to use as parents for placing the colorbar.
1405 %(_make_axes_kw_doc)s
1406
1407 Returns
1408 -------
1409 cax : `~matplotlib.axes.Axes`
1410 The child Axes.
1411 kwargs : dict
1412 The reduced keyword dictionary to be passed when creating the colorbar
1413 instance.
1414 """
1415 loc_settings = _normalize_location_orientation(location, orientation)
1416 # put appropriate values into the kwargs dict for passing back to
1417 # the Colorbar class
1418 kwargs['orientation'] = loc_settings['orientation']
1419 location = kwargs['ticklocation'] = loc_settings['location']
1420
1421 anchor = kwargs.pop('anchor', loc_settings['anchor'])
1422 panchor = kwargs.pop('panchor', loc_settings['panchor'])
1423 aspect0 = aspect
1424 # turn parents into a list if it is not already. Note we cannot
1425 # use .flatten or .ravel as these copy the references rather than
1426 # reuse them, leading to a memory leak
1427 if isinstance(parents, np.ndarray):
1428 parents = list(parents.flat)
1429 elif np.iterable(parents):
1430 parents = list(parents)
1431 else:
1432 parents = [parents]
1433
1434 fig = parents[0].get_figure()
1435
1436 pad0 = 0.05 if fig.get_constrained_layout() else loc_settings['pad']
1437 pad = kwargs.pop('pad', pad0)
1438
1439 if not all(fig is ax.get_figure() for ax in parents):
1440 raise ValueError('Unable to create a colorbar Axes as not all '
1441 'parents share the same figure.')
1442
1443 # take a bounding box around all of the given Axes
1444 parents_bbox = mtransforms.Bbox.union(
1445 [ax.get_position(original=True).frozen() for ax in parents])
1446
1447 pb = parents_bbox
1448 if location in ('left', 'right'):
1449 if location == 'left':
1450 pbcb, _, pb1 = pb.splitx(fraction, fraction + pad)

Callers

nothing calls this directly

Calls 15

unionMethod · 0.80
splitxMethod · 0.80
anchoredMethod · 0.80
shrunkMethod · 0.80
splityMethod · 0.80
_set_positionMethod · 0.80
add_axesMethod · 0.80
popMethod · 0.45
get_figureMethod · 0.45
frozenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…