Skip to content

Commit

Permalink
Fix matplotlib#4700: Use overlay by default
Browse files Browse the repository at this point in the history
  • Loading branch information
mdboom committed Nov 27, 2015
1 parent ba35b45 commit e349b8a
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 79 deletions.
19 changes: 10 additions & 9 deletions lib/matplotlib/colors.py
Expand Up @@ -1595,7 +1595,7 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):

return intensity

def shade(self, data, cmap, norm=None, blend_mode='hsv', vmin=None,
def shade(self, data, cmap, norm=None, blend_mode='overlay', vmin=None,
vmax=None, vert_exag=1, dx=1, dy=1, fraction=1, **kwargs):
"""
Combine colormapped data values with an illumination intensity map
Expand All @@ -1615,15 +1615,16 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv', vmin=None,
The normalization used to scale values before colormapping. If
None, the input will be linearly scaled between its min and max.
blend_mode : {'hsv', 'overlay', 'soft'} or callable, optional
The type of blending used to combine the colormapped data values
with the illumination intensity. For backwards compatibility, this
defaults to "hsv". Note that for most topographic surfaces,
The type of blending used to combine the colormapped data
values with the illumination intensity. Default is
"overlay". Note that for most topographic surfaces,
"overlay" or "soft" appear more visually realistic. If a
user-defined function is supplied, it is expected to combine an
MxNx3 RGB array of floats (ranging 0 to 1) with an MxNx1 hillshade
array (also 0 to 1). (Call signature `func(rgb, illum, **kwargs)`)
Additional kwargs supplied to this function will be passed on to
the *blend_mode* function.
user-defined function is supplied, it is expected to
combine an MxNx3 RGB array of floats (ranging 0 to 1) with
an MxNx1 hillshade array (also 0 to 1). (Call signature
`func(rgb, illum, **kwargs)`) Additional kwargs supplied
to this function will be passed on to the *blend_mode*
function.
vmin : scalar or None, optional
The minimum value used in colormapping *data*. If *None* the
minimum value in *data* is used. If *norm* is specified, then this
Expand Down
145 changes: 75 additions & 70 deletions lib/matplotlib/tests/test_colors.py
Expand Up @@ -352,41 +352,44 @@ def test_light_source_shading_default():
rgb = ls.shade(z, cmap)

# Result stored transposed and rounded for for more compact display...
expect = np.array([[[0.87, 0.85, 0.90, 0.90, 0.82, 0.62, 0.34, 0.00],
[0.85, 0.94, 0.99, 1.00, 1.00, 0.96, 0.62, 0.17],
[0.90, 0.99, 1.00, 1.00, 1.00, 1.00, 0.71, 0.33],
[0.90, 1.00, 1.00, 1.00, 1.00, 0.98, 0.51, 0.29],
[0.82, 1.00, 1.00, 1.00, 1.00, 0.64, 0.25, 0.13],
[0.62, 0.96, 1.00, 0.98, 0.64, 0.22, 0.06, 0.03],
[0.34, 0.62, 0.71, 0.51, 0.25, 0.06, 0.00, 0.01],
[0.00, 0.17, 0.33, 0.29, 0.13, 0.03, 0.01, 0.00]],

[[0.87, 0.79, 0.83, 0.80, 0.66, 0.44, 0.23, 0.00],
[0.79, 0.88, 0.93, 0.92, 0.83, 0.66, 0.38, 0.10],
[0.83, 0.93, 0.99, 1.00, 0.92, 0.75, 0.40, 0.18],
[0.80, 0.92, 1.00, 0.99, 0.93, 0.75, 0.28, 0.14],
[0.66, 0.83, 0.92, 0.93, 0.87, 0.44, 0.12, 0.06],
[0.44, 0.66, 0.75, 0.75, 0.44, 0.12, 0.03, 0.01],
[0.23, 0.38, 0.40, 0.28, 0.12, 0.03, 0.00, 0.00],
[0.00, 0.10, 0.18, 0.14, 0.06, 0.01, 0.00, 0.00]],

[[0.87, 0.75, 0.78, 0.73, 0.55, 0.33, 0.16, 0.00],
[0.75, 0.85, 0.90, 0.86, 0.71, 0.48, 0.23, 0.05],
[0.78, 0.90, 0.98, 1.00, 0.82, 0.51, 0.21, 0.08],
[0.73, 0.86, 1.00, 0.97, 0.84, 0.47, 0.11, 0.05],
[0.55, 0.71, 0.82, 0.84, 0.71, 0.20, 0.03, 0.01],
[0.33, 0.48, 0.51, 0.47, 0.20, 0.02, 0.00, 0.00],
[0.16, 0.23, 0.21, 0.11, 0.03, 0.00, 0.00, 0.00],
[0.00, 0.05, 0.08, 0.05, 0.01, 0.00, 0.00, 0.00]],

[[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00]]]).T
expect = np.array(
[[[0.00, 0.45, 0.90, 0.90, 0.82, 0.62, 0.28, 0.00],
[0.45, 0.94, 0.99, 1.00, 1.00, 0.96, 0.65, 0.17],
[0.90, 0.99, 1.00, 1.00, 1.00, 1.00, 0.94, 0.35],
[0.90, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 0.49],
[0.82, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 0.41],
[0.62, 0.96, 1.00, 1.00, 1.00, 1.00, 0.90, 0.07],
[0.28, 0.65, 0.94, 1.00, 1.00, 0.90, 0.35, 0.01],
[0.00, 0.17, 0.35, 0.49, 0.41, 0.07, 0.01, 0.00]],

[[0.00, 0.28, 0.59, 0.72, 0.62, 0.40, 0.18, 0.00],
[0.28, 0.78, 0.93, 0.92, 0.83, 0.66, 0.39, 0.11],
[0.59, 0.93, 0.99, 1.00, 0.92, 0.75, 0.50, 0.21],
[0.72, 0.92, 1.00, 0.99, 0.93, 0.76, 0.51, 0.18],
[0.62, 0.83, 0.92, 0.93, 0.87, 0.68, 0.42, 0.08],
[0.40, 0.66, 0.75, 0.76, 0.68, 0.52, 0.23, 0.02],
[0.18, 0.39, 0.50, 0.51, 0.42, 0.23, 0.00, 0.00],
[0.00, 0.11, 0.21, 0.18, 0.08, 0.02, 0.00, 0.00]],

[[0.00, 0.18, 0.38, 0.46, 0.39, 0.26, 0.11, 0.00],
[0.18, 0.50, 0.70, 0.75, 0.64, 0.44, 0.25, 0.07],
[0.38, 0.70, 0.91, 0.98, 0.81, 0.51, 0.29, 0.13],
[0.46, 0.75, 0.98, 0.96, 0.84, 0.48, 0.22, 0.12],
[0.39, 0.64, 0.81, 0.84, 0.71, 0.31, 0.11, 0.05],
[0.26, 0.44, 0.51, 0.48, 0.31, 0.10, 0.03, 0.01],
[0.11, 0.25, 0.29, 0.22, 0.11, 0.03, 0.00, 0.00],
[0.00, 0.07, 0.13, 0.12, 0.05, 0.01, 0.00, 0.00]],

[[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00]]
]).T

if (V(np.__version__) == V('1.9.0')):
# Numpy 1.9.0 uses a 2. order algorithm on the edges by default
# This was changed back again in 1.9.1
Expand Down Expand Up @@ -414,41 +417,43 @@ def test_light_source_masked_shading():
rgb = ls.shade(z, cmap)

# Result stored transposed and rounded for for more compact display...
expect = np.array([[[0.90, 0.88, 0.91, 0.91, 0.84, 0.64, 0.36, 0.00],
[0.88, 0.96, 1.00, 1.00, 1.00, 0.97, 0.64, 0.18],
[0.91, 1.00, 1.00, 1.00, 1.00, 1.00, 0.74, 0.34],
[0.91, 1.00, 1.00, 0.00, 0.00, 1.00, 0.52, 0.30],
[0.84, 1.00, 1.00, 0.00, 0.00, 1.00, 0.25, 0.13],
[0.64, 0.97, 1.00, 1.00, 1.00, 0.23, 0.07, 0.03],
[0.36, 0.64, 0.74, 0.52, 0.25, 0.07, 0.00, 0.01],
[0.00, 0.18, 0.34, 0.30, 0.13, 0.03, 0.01, 0.00]],

[[0.90, 0.82, 0.85, 0.82, 0.68, 0.46, 0.24, 0.00],
[0.82, 0.91, 0.95, 0.93, 0.85, 0.68, 0.39, 0.10],
[0.85, 0.95, 1.00, 0.78, 0.78, 0.77, 0.42, 0.18],
[0.82, 0.93, 0.78, 0.00, 0.00, 0.78, 0.30, 0.15],
[0.68, 0.85, 0.78, 0.00, 0.00, 0.78, 0.13, 0.06],
[0.46, 0.68, 0.77, 0.78, 0.78, 0.13, 0.03, 0.01],
[0.24, 0.39, 0.42, 0.30, 0.13, 0.03, 0.00, 0.00],
[0.00, 0.10, 0.18, 0.15, 0.06, 0.01, 0.00, 0.00]],

[[0.90, 0.79, 0.81, 0.76, 0.58, 0.35, 0.17, 0.00],
[0.79, 0.88, 0.92, 0.88, 0.73, 0.50, 0.24, 0.05],
[0.81, 0.92, 1.00, 0.50, 0.50, 0.53, 0.22, 0.09],
[0.76, 0.88, 0.50, 0.00, 0.00, 0.50, 0.12, 0.05],
[0.58, 0.73, 0.50, 0.00, 0.00, 0.50, 0.03, 0.01],
[0.35, 0.50, 0.53, 0.50, 0.50, 0.02, 0.00, 0.00],
[0.17, 0.24, 0.22, 0.12, 0.03, 0.00, 0.00, 0.00],
[0.00, 0.05, 0.09, 0.05, 0.01, 0.00, 0.00, 0.00]],

[[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 0.00, 0.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 0.00, 0.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00]]]).T
expect = np.array(
[[[0.00, 0.46, 0.91, 0.91, 0.84, 0.64, 0.29, 0.00],
[0.46, 0.96, 1.00, 1.00, 1.00, 0.97, 0.67, 0.18],
[0.91, 1.00, 1.00, 1.00, 1.00, 1.00, 0.96, 0.36],
[0.91, 1.00, 1.00, 0.00, 0.00, 1.00, 1.00, 0.51],
[0.84, 1.00, 1.00, 0.00, 0.00, 1.00, 1.00, 0.44],
[0.64, 0.97, 1.00, 1.00, 1.00, 1.00, 0.94, 0.09],
[0.29, 0.67, 0.96, 1.00, 1.00, 0.94, 0.38, 0.01],
[0.00, 0.18, 0.36, 0.51, 0.44, 0.09, 0.01, 0.00]],

[[0.00, 0.29, 0.61, 0.75, 0.64, 0.41, 0.18, 0.00],
[0.29, 0.81, 0.95, 0.93, 0.85, 0.68, 0.40, 0.11],
[0.61, 0.95, 1.00, 0.78, 0.78, 0.77, 0.52, 0.22],
[0.75, 0.93, 0.78, 0.00, 0.00, 0.78, 0.54, 0.19],
[0.64, 0.85, 0.78, 0.00, 0.00, 0.78, 0.45, 0.08],
[0.41, 0.68, 0.77, 0.78, 0.78, 0.55, 0.25, 0.02],
[0.18, 0.40, 0.52, 0.54, 0.45, 0.25, 0.00, 0.00],
[0.00, 0.11, 0.22, 0.19, 0.08, 0.02, 0.00, 0.00]],

[[0.00, 0.19, 0.39, 0.48, 0.41, 0.26, 0.12, 0.00],
[0.19, 0.52, 0.73, 0.78, 0.66, 0.46, 0.26, 0.07],
[0.39, 0.73, 0.95, 0.50, 0.50, 0.53, 0.30, 0.14],
[0.48, 0.78, 0.50, 0.00, 0.00, 0.50, 0.23, 0.12],
[0.41, 0.66, 0.50, 0.00, 0.00, 0.50, 0.11, 0.05],
[0.26, 0.46, 0.53, 0.50, 0.50, 0.11, 0.03, 0.01],
[0.12, 0.26, 0.30, 0.23, 0.11, 0.03, 0.00, 0.00],
[0.00, 0.07, 0.14, 0.12, 0.05, 0.01, 0.00, 0.00]],

[[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 0.00, 0.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 0.00, 0.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00],
[1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00, 1.00]],
]).T

assert_array_almost_equal(rgb, expect, decimal=2)

Expand Down

0 comments on commit e349b8a

Please sign in to comment.