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

Skip to content

Commit 56d509f

Browse files
authored
Merge pull request #17481 from QuLogic/masked-shading
Fix LightSource.shade on fully unmasked array.
2 parents 5ab1352 + ac400b5 commit 56d509f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

lib/matplotlib/colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,7 @@ def shade_rgb(self, rgb, elevation, fraction=1., blend_mode='hsv',
19361936
.format(lookup.keys)) from err
19371937

19381938
# Only apply result where hillshade intensity isn't masked
1939-
if hasattr(intensity, 'mask'):
1939+
if np.ma.is_masked(intensity):
19401940
mask = intensity.mask[..., 0]
19411941
for i in range(3):
19421942
blend[..., i][mask] = rgb[..., i][mask]

lib/matplotlib/tests/test_colors.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,19 @@ def test_light_source_shading_default():
692692
assert_array_almost_equal(rgb, expect, decimal=2)
693693

694694

695+
def test_light_source_shading_empty_mask():
696+
y, x = np.mgrid[-1.2:1.2:8j, -1.2:1.2:8j]
697+
z0 = 10 * np.cos(x**2 + y**2)
698+
z1 = np.ma.array(z0)
699+
700+
cmap = plt.cm.copper
701+
ls = mcolors.LightSource(315, 45)
702+
rgb0 = ls.shade(z0, cmap)
703+
rgb1 = ls.shade(z1, cmap)
704+
705+
assert_array_almost_equal(rgb0, rgb1)
706+
707+
695708
# Numpy 1.9.1 fixed a bug in masked arrays which resulted in
696709
# additional elements being masked when calculating the gradient thus
697710
# the output is different with earlier numpy versions.

0 commit comments

Comments
 (0)