-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Keep using a single dividers LineCollection instance in colorbar. #17834
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
``Colorbar.dividers`` changes | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
This attribute is now always a `.LineCollection` -- an empty one if | ||
``drawedges`` is False. Its default colors and linewidth (:rc:`axes.edgecolor`, | ||
:rc:`axes.linewidth`) are now resolved at instantiation time, not at draw time. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -353,10 +353,9 @@ class ColorbarBase: | |
ax : `~matplotlib.axes.Axes` | ||
The `~.axes.Axes` instance in which the colorbar is drawn. | ||
lines : list | ||
A list of `.LineCollection` if lines were drawn, otherwise | ||
an empty list. | ||
A list of `.LineCollection` (empty if no lines were drawn). | ||
dividers : `.LineCollection` | ||
A LineCollection if *drawedges* is ``True``, otherwise ``None``. | ||
A LineCollection (empty if *drawedges* is ``False``). | ||
|
||
Parameters | ||
---------- | ||
|
@@ -464,12 +463,18 @@ def __init__(self, ax, cmap=None, | |
linewidth=mpl.rcParams['axes.linewidth'], closed=True, zorder=2) | ||
ax.add_artist(self.outline) | ||
self.outline.set(clip_box=None, clip_path=None) | ||
|
||
self.patch = mpatches.Polygon( | ||
np.empty((0, 2)), | ||
color=mpl.rcParams['axes.facecolor'], linewidth=0.01, zorder=-1) | ||
ax.add_artist(self.patch) | ||
|
||
self.dividers = None | ||
self.dividers = collections.LineCollection( | ||
[], | ||
colors=[mpl.rcParams['axes.edgecolor']], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this change the time of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The same "change in resolution time" occurred in #15981, where it is arguably a bugfix. |
||
linewidths=[0.5 * mpl.rcParams['axes.linewidth']]) | ||
self.ax.add_collection(self.dividers) | ||
|
||
self.locator = None | ||
self.formatter = None | ||
self._manual_tick_data_values = None | ||
|
@@ -819,18 +824,13 @@ def _add_solids(self, X, Y, C): | |
if self.solids is not None: | ||
self.solids.remove() | ||
self.solids = col | ||
if self.dividers is not None: | ||
self.dividers.remove() | ||
self.dividers = None | ||
|
||
if self.drawedges: | ||
linewidths = (0.5 * mpl.rcParams['axes.linewidth'],) | ||
self.dividers = collections.LineCollection( | ||
self._edges(X, Y), | ||
colors=(mpl.rcParams['axes.edgecolor'],), | ||
linewidths=linewidths) | ||
self.ax.add_collection(self.dividers) | ||
elif len(self._y) >= self.n_rasterize: | ||
self.solids.set_rasterized(True) | ||
self.dividers.set_segments(self._edges(X, Y)) | ||
else: | ||
self.dividers.set_segments([]) | ||
if len(self._y) >= self.n_rasterize: | ||
self.solids.set_rasterized(True) | ||
|
||
def add_lines(self, levels, colors, linewidths, erase=True): | ||
""" | ||
|
@@ -1335,7 +1335,6 @@ def update_bruteforce(self, mappable): | |
self.ax.add_artist(self.patch) | ||
self.solids = None | ||
self.lines = [] | ||
self.dividers = None | ||
self.update_normal(mappable) | ||
self.draw_all() | ||
if isinstance(self.mappable, contour.ContourSet): | ||
|
@@ -1664,16 +1663,7 @@ def _add_solids(self, X, Y, C): | |
|
||
self.solids_patches = patches | ||
|
||
if self.dividers is not None: | ||
self.dividers.remove() | ||
self.dividers = None | ||
|
||
if self.drawedges: | ||
self.dividers = collections.LineCollection( | ||
self._edges(X, Y), | ||
colors=(mpl.rcParams['axes.edgecolor'],), | ||
linewidths=(0.5 * mpl.rcParams['axes.linewidth'],)) | ||
self.ax.add_collection(self.dividers) | ||
self.dividers.set_segments(self._edges(X, Y) if self.drawedges else []) | ||
|
||
|
||
def colorbar_factory(cax, mappable, **kwargs): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this get an API change note?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is an API break because previously the attribute could be LineCollection or None, and now it's always LineCollection, so we don't add more types to handle.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically, people could have checked
cb.dividers is None
, which now would have to be changed tonot cb.dividers
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure, added changelog