Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 03a542e

Browse filesBrowse files
authored
Merge pull request #18521 from anntzer/cbarinline
Inline some helpers in ColorbarBase.
2 parents 986bbfe + 6716429 commit 03a542e
Copy full SHA for 03a542e

File tree

Expand file treeCollapse file tree

1 file changed

+15
-44
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+15
-44
lines changed

‎lib/matplotlib/colorbar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colorbar.py
+15-44Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -525,28 +525,29 @@ def draw_all(self):
525525
Calculate any free parameters based on the current cmap and norm,
526526
and do all the drawing.
527527
"""
528-
# sets self._boundaries and self._values in real data units.
529-
# takes into account extend values:
528+
self._config_axis() # Inline it after deprecation elapses.
529+
# Set self._boundaries and self._values, including extensions.
530530
self._process_values()
531-
# sets self.vmin and vmax in data units, but just for the part of the
532-
# colorbar that is not part of the extend patch:
533-
self._find_range()
534-
# returns the X and Y mesh, *but* this was/is in normalized units:
531+
# Set self.vmin and self.vmax to first and last boundary, excluding
532+
# extensions.
533+
self.vmin, self.vmax = self._boundaries[self._inside][[0, -1]]
534+
# Compute the X/Y mesh, assuming vertical orientation.
535535
X, Y = self._mesh()
536-
C = self._values[:, np.newaxis]
537-
538-
self._config_axis() # Inline it after deprecation elapses.
536+
# Extract bounding polygon (the last entry's value (X[0, 1]) doesn't
537+
# matter, it just matches the CLOSEPOLY code).
538+
x = np.concatenate([X[[0, 1, -2, -1], 0], X[[-1, -2, 1, 0, 0], 1]])
539+
y = np.concatenate([Y[[0, 1, -2, -1], 0], Y[[-1, -2, 1, 0, 0], 1]])
540+
xy = (np.column_stack([x, y]) if self.orientation == 'vertical' else
541+
np.column_stack([y, x])) # Apply orientation.
539542
# Configure axes limits, patch, and outline.
540-
xy = self._outline(X, Y)
541543
xmin, ymin = xy.min(axis=0)
542544
xmax, ymax = xy.max(axis=0)
543545
self.ax.set(xlim=(xmin, xmax), ylim=(ymin, ymax))
544546
self.outline.set_xy(xy)
545547
self.patch.set_xy(xy)
546548
self.update_ticks()
547-
548549
if self.filled:
549-
self._add_solids(X, Y, C)
550+
self._add_solids(X, Y, self._values[:, np.newaxis])
550551

551552
@cbook.deprecated("3.3")
552553
def config_axis(self):
@@ -795,19 +796,6 @@ def set_label(self, label, *, loc=None, **kwargs):
795796
self.ax.set_xlabel(label, **kwargs)
796797
self.stale = True
797798

798-
def _outline(self, X, Y):
799-
"""
800-
Return *x*, *y* arrays of colorbar bounding polygon,
801-
taking orientation into account.
802-
"""
803-
N = X.shape[0]
804-
ii = [0, 1, N - 2, N - 1, 2 * N - 1, 2 * N - 2, N + 1, N, 0]
805-
x = X.T.reshape(-1)[ii]
806-
y = Y.T.reshape(-1)[ii]
807-
return (np.column_stack([y, x])
808-
if self.orientation == 'horizontal' else
809-
np.column_stack([x, y]))
810-
811799
def _edges(self, X, Y):
812800
"""Return the separator line segments; helper for _add_solids."""
813801
N = X.shape[0]
@@ -1003,24 +991,6 @@ def _process_values(self, b=None):
1003991
b[-1] = b[-1] + 1
1004992
self._process_values(b)
1005993

1006-
def _find_range(self):
1007-
"""
1008-
Set :attr:`vmin` and :attr:`vmax` attributes to the first and
1009-
last boundary excluding extended end boundaries.
1010-
"""
1011-
b = self._boundaries[self._inside]
1012-
self.vmin = b[0]
1013-
self.vmax = b[-1]
1014-
1015-
def _central_N(self):
1016-
"""Return the number of boundaries excluding end extensions."""
1017-
nb = len(self._boundaries)
1018-
if self.extend == 'both':
1019-
nb -= 2
1020-
elif self.extend in ('min', 'max'):
1021-
nb -= 1
1022-
return nb
1023-
1024994
def _get_extension_lengths(self, frac, automin, automax, default=0.05):
1025995
"""
1026996
Return the lengths of colorbar extensions.
@@ -1127,7 +1097,8 @@ def _mesh(self):
11271097
norm.vmax = self.vmax
11281098
x = np.array([0.0, 1.0])
11291099
if self.spacing == 'uniform':
1130-
y = self._uniform_y(self._central_N())
1100+
n_boundaries_no_extensions = len(self._boundaries[self._inside])
1101+
y = self._uniform_y(n_boundaries_no_extensions)
11311102
else:
11321103
y = self._proportional_y()
11331104
xmid = np.array([0.5])

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.