diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 821732dc318c..d98ef45e60af 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -1403,10 +1403,13 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15, anchor = kw.pop('anchor', loc_settings['anchor']) panchor = kw.pop('panchor', loc_settings['panchor']) aspect0 = aspect - # turn parents into a list if it is not already. We do this w/ np - # because `plt.subplots` can return an ndarray and is natural to - # pass to `colorbar`. - parents = np.atleast_1d(parents).ravel() + # turn parents into a list if it is not already. Note we cannot + # use .flatten or .ravel as these copy the references rather than + # reuse them, leading to a memory leak + if isinstance(parents, np.ndarray): + parents = list(parents.flat) + elif not isinstance(parents, list): + parents = [parents] fig = parents[0].get_figure() pad0 = 0.05 if fig.get_constrained_layout() else loc_settings['pad'] @@ -1454,8 +1457,8 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15, # tell the parent it has a colorbar a._colorbars += [cax] cax._colorbar_info = dict( - location=location, parents=parents, + location=location, shrink=shrink, anchor=anchor, panchor=panchor,
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: