8000 Merge pull request #8812 from efiring/colorbar_divide_by_zero · matplotlib/matplotlib@fcce35d · GitHub
[go: up one dir, main page]

Skip to content

Commit fcce35d

Browse files
authored
Merge pull request #8812 from efiring/colorbar_divide_by_zero
BUGS: in colorbar: divide-by-zero, and undesired masked array
2 parents 1572cca + 85dfccd commit fcce35d

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
@@ -809,6 +809,7 @@ def _proportional_y(self):
809809
y = y / (self._boundaries[-1] - self._boundaries[0])
810810
else:
811811
y = self.norm(self._boundaries.copy())
812+
y = np.ma.filled(y, np.nan)
812813
if self.extend == 'min':
813814
# Exclude leftmost interval of y.
814815
clen = y[-1] - y[1]
@@ -819,21 +820,22 @@ def _proportional_y(self):
819820
clen = y[-2] - y[0]
820821
automin = (y[1] - y[0]) / clen
821822
automax = (y[-2] - y[-3]) / clen
822-
else:
823+
elif self.extend == 'both':
823824
# Exclude leftmost and rightmost intervals in y.
824825
clen = y[-2] - y[1]
825826
automin = (y[2] - y[1]) / clen
826827
automax = (y[-2] - y[-3]) / clen
827-
extendlength = self._get_extension_lengths(self.extendfrac,
828-
automin, automax,
829-
default=0.05)
828+
if self.extend in ('both', 'min', 'max'):
829+
extendlength = self._get_extension_lengths(self.extendfrac,
830+
automin, automax,
831+
default=0.05)
830832
if self.extend in ('both', 'min'):
831833
y[0] = 0. - extendlength[0]
832834
if self.extend in ('both', 'max'):
833835
y[-1] = 1. + extendlength[1]
834836
yi = y[self._inside]
835837
norm = colors.Normalize(yi[0], yi[-1])
836-
y[self._inside] = norm(yi)
838+
y[self._inside] = np.ma.filled(norm(yi), np.nan)
837839
return y
838840

839841
def _mesh(self):

0 commit comments

Comments
 (0)
0