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)
| 1391 | |
| 1392 | @_docstring.interpd |
| 1393 | def 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) |
nothing calls this directly
no test coverage detected
searching dependent graphs…