Skip to content

MNT: privatize colorbar attr #21933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ class Colorbar:

n_rasterize = 50 # rasterize solids if number of colors >= n_rasterize

@_api.delete_parameter("3.6", "filled")
def __init__(self, ax, mappable=None, *, cmap=None,
norm=None,
alpha=None,
Expand Down Expand Up @@ -450,7 +451,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
self.spacing = spacing
self.orientation = orientation
self.drawedges = drawedges
self.filled = filled
self._filled = filled
self.extendfrac = extendfrac
self.extendrect = extendrect
self.solids = None
Expand Down Expand Up @@ -499,7 +500,7 @@ def __init__(self, ax, mappable=None, *, cmap=None,
self.formatter = ticker.StrMethodFormatter(format)
else:
self.formatter = format # Assume it is a Formatter or None
self.draw_all()
self._draw_all()

if isinstance(mappable, contour.ContourSet) and not mappable.filled:
self.add_lines(mappable)
Expand Down Expand Up @@ -530,6 +531,8 @@ def _cbar_cla(self):
# Also remove ._patch after deprecation elapses.
patch = _api.deprecate_privatize_attribute("3.5", alternative="ax")

filled = _api.deprecate_privatize_attribute("3.6")

def update_normal(self, mappable):
"""
Update solid patches, lines, etc.
Expand All @@ -551,14 +554,22 @@ def update_normal(self, mappable):
self.norm = mappable.norm
self._reset_locator_formatter_scale()

self.draw_all()
self._draw_all()
if isinstance(self.mappable, contour.ContourSet):
CS = self.mappable
if not CS.filled:
self.add_lines(CS)
self.stale = True

@_api.deprecated("3.6", alternative="fig.draw_without_rendering()")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does draw_without_rendering() actually hit this path? I guess so when the axes this colorbar is attached to gets called? But, it isn't obvious to me.

def draw_all(self):
"""
Calculate any free parameters based on the current cmap and norm,
and do all the drawing.
"""
self._draw_all()

def _draw_all(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we rename this to _update_parameters() or something like that instead? A quick search shows that the only other draw_all() is in pyplot to update all stale figures, which is very different from this draw_all.

As an aside, I'm wondering if this information should actually be in a draw(self, renderer) method instead (it looks like Colorbar doesn't have a draw() currently), that can then call self.ax.draw() after these updates.

"""
Calculate any free parameters based on the current cmap and norm,
and do all the drawing.
Expand Down Expand Up @@ -599,7 +610,7 @@ def draw_all(self):
# boundary norms + uniform spacing requires a manual locator.
self.update_ticks()

if self.filled:
if self._filled:
ind = np.arange(len(self._values))
if self._extend_lower():
ind = ind[1:]
Expand Down Expand Up @@ -671,7 +682,7 @@ def _do_extends(self, extendlen):

# xyout is the path for the spine:
self.outline.set_xy(xyout)
if not self.filled:
if not self._filled:
return

# Make extend triangles or rectangles filled patches. These are
Expand Down