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

Skip to content

Commit f374383

Browse files
committed
Fix calculation of aspect for hillshading.
1 parent 108eac7 commit f374383

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/matplotlib/colors.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,9 +1547,11 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
15471547
# consistent to what `imshow` assumes, as well.
15481548
dy = -dy
15491549

1550+
#-- Calculate the intensity from the illumination angle
15501551
dy, dx = np.gradient(vert_exag * elevation, dy, dx)
1552+
# The aspect is defined by the _downhill_ direction, thus the negative
1553+
aspect = np.arctan2(-dy, -dx)
15511554
slope = 0.5 * np.pi - np.arctan(np.hypot(dx, dy))
1552-
aspect = np.arctan2(dx, dy)
15531555
intensity = (np.sin(alt) * np.sin(slope)
15541556
+ np.cos(alt) * np.cos(slope)
15551557
* np.cos(az - aspect))
@@ -1565,7 +1567,7 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
15651567
intensity -= imin
15661568
intensity /= (imax - imin)
15671569
else:
1568-
# If constant slope, keep relative scaling
1570+
# If constant slope, keep relative scaling
15691571
# (i.e. flat should be 0.5, fully occluded 0, etc.)
15701572
intensity = (intensity + 1) / 2
15711573

0 commit comments

Comments
 (0)