Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 108eac7

Browse files
committed
Avoid potential divide by zero in LightSource.hillshade
1 parent 52434ff commit 108eac7

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

lib/matplotlib/colors.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,8 +1561,13 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
15611561
np.clip(intensity, imin, imax, intensity)
15621562

15631563
# Rescale to 0-1, keeping range before contrast stretch
1564-
intensity -= imin
1565-
intensity /= (imax - imin)
1564+
if imax > imin:
1565+
intensity -= imin
1566+
intensity /= (imax - imin)
1567+
else:
1568+
# If constant slope, keep relative scaling
1569+
# (i.e. flat should be 0.5, fully occluded 0, etc.)
1570+
intensity = (intensity + 1) / 2
15661571

15671572
return intensity
15681573

0 commit comments

Comments
 (0)