diff --git a/doc/api/next_api_changes/behavior/20054-JMK.rst b/doc/api/next_api_changes/behavior/20054-JMK.rst index d27ce486c8bb..0b9fb193df64 100644 --- a/doc/api/next_api_changes/behavior/20054-JMK.rst +++ b/doc/api/next_api_changes/behavior/20054-JMK.rst @@ -5,3 +5,8 @@ If a colorbar has lines added to it (e.g. for contour lines), these will no longer be clipped. This is an improvement for lines on the edge of the colorbar, but could lead to lines off the colorbar if the limits of the colorbar are changed. + +``Colorbar.patch`` is deprecated +================================ + +This attribute is not correctly updated anymore. diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 6285f412053c..2e0aa0ad3c93 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -451,10 +451,11 @@ def __init__(self, ax, mappable=None, *, cmap=None, spine.set_visible(False) self.outline = self.ax.spines['outline'] = _ColorbarSpine(self.ax) self._short_axis().set_visible(False) - self.patch = mpatches.Polygon( + # Only kept for backcompat; remove after deprecation of .patch elapses. + self._patch = mpatches.Polygon( np.empty((0, 2)), color=mpl.rcParams['axes.facecolor'], linewidth=0.01, zorder=-1) - ax.add_artist(self.patch) + ax.add_artist(self._patch) self.dividers = collections.LineCollection( [], @@ -487,6 +488,9 @@ def __init__(self, ax, mappable=None, *, cmap=None, if isinstance(mappable, contour.ContourSet) and not mappable.filled: self.add_lines(mappable) + # Also remove ._patch after deprecation elapses. + patch = _api.deprecate_privatize_attribute("3.5") + def update_normal(self, mappable): """ Update solid patches, lines, etc.