Skip to content

Commit 85dfccd

Browse files
committed
BUGS: in colorbar: divide-by-zero, and undesired masked array
Closes #8534 (divide-by-zero warning). Also fixes a bug that became evident with #8801, which causes pcolormesh to fail if X or Y is a masked array. Although masked arrays are not supported by pcolormesh, previously it would ignore the mask. Locators always return masked arrays, so the present commit explicitly converts to an ndarray the Locator output used by proportional colorbars.
1 parent ee030cb commit 85dfccd

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/matplotlib/colorbar.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -801,6 +801,7 @@ def _proportional_y(self):
801801
y = y / (self._boundaries[-1] - self._boundaries[0])
802802
else:
803803
y = self.norm(self._boundaries.copy())
804+
y = np.ma.filled(y, np.nan)
804805
if self.extend == 'min':
805806
# Exclude leftmost interval of y.
806807
clen = y[-1] - y[1]
@@ -811,21 +812,22 @@ def _proportional_y(self):
811812
clen = y[-2] - y[0]
812813
automin = (y[1] - y[0]) / clen
813814
automax = (y[-2] - y[-3]) / clen
814-
else:
815+
elif self.extend == 'both':
815816
# Exclude leftmost and rightmost intervals in y.
816817
clen = y[-2] - y[1]
817818
automin = (y[2] - y[1]) / clen
818819
automax = (y[-2] - y[-3]) / clen
819-
extendlength = self._get_extension_lengths(self.extendfrac,
820-
automin, automax,
821-
default=0.05)
820+
if self.extend in ('both', 'min', 'max'):
821+
extendlength = self._get_extension_lengths(self.extendfrac,
822+
automin, automax,
823+
default=0.05)
822824
if self.extend in ('both', 'min'):
823825
y[0] = 0. - extendlength[0]
824826
if self.extend in ('both', 'max'):
825827
y[-1] = 1. + extendlength[1]
826828
yi = y[self._inside]
827829
norm = colors.Normalize(yi[0], yi[-1])
828-
y[self._inside] = norm(yi)
830+
y[self._inside] = np.ma.filled(norm(yi), np.nan)
829831
return y
830832

831833
def _mesh(self):

0 commit comments

Comments
 (0)