Skip to content

Commit ab40a2f

Browse files
committed
Added *vmin* and *vmax* arguments to LightSource.shade
1 parent ba1f492 commit ab40a2f

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

examples/specialty_plots/advanced_hillshading.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def avoid_outliers():
4040
ax1.imshow(rgb)
4141
ax1.set_title('Full range of data')
4242

43-
rgb = ls.shade(z, plt.cm.copper, norm=Normalize(-10, 10)) # Note the norm!!
43+
rgb = ls.shade(z, plt.cm.copper, vmin=-10, vmax=10)
4444
ax2.imshow(rgb)
4545
ax2.set_title('Manually set range')
4646

lib/matplotlib/colors.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,8 +1574,8 @@ def hillshade(self, elevation, vert_exag=1, dx=1, dy=1, fraction=1.):
15741574

15751575
return intensity
15761576

1577-
def shade(self, data, cmap, norm=None, blend_mode='hsv',
1578-
vert_exag=1, dx=1, dy=1, fraction=1, **kwargs):
1577+
def shade(self, data, cmap, norm=None, blend_mode='hsv', vmin=None,
1578+
vmax=None, vert_exag=1, dx=1, dy=1, fraction=1, **kwargs):
15791579
"""
15801580
Combine colormapped data values with an illumination intensity map
15811581
(a.k.a. "hillshade") of the values.
@@ -1603,6 +1603,14 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv',
16031603
array (also 0 to 1). (Call signature `func(rgb, illum, **kwargs)`)
16041604
Additional kwargs supplied to this function will be passed on to
16051605
the *blend_mode* function.
1606+
vmin : scalar or None, optional
1607+
The minimum value used in colormapping *data*. If *None* the
1608+
minimum value in *data* is used. If *norm* is specified, then this
1609+
argument will be ignored.
1610+
vmax : scalar or None, optional
1611+
The maximum value used in colormapping *data*. If *None* the
1612+
maximum value in *data* is used. If *norm* is specified, then this
1613+
argument will be ignored.
16061614
vert_exag : number, optional
16071615
The amount to exaggerate the elevation values by when calculating
16081616
illumination. This can be used either to correct for differences in
@@ -1626,8 +1634,12 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv',
16261634
rgba : ndarray
16271635
An MxNx4 array of floats ranging between 0-1.
16281636
"""
1637+
if vmin is None:
1638+
vmin = data.min()
1639+
if vmax is None:
1640+
vmax = data.max()
16291641
if norm is None:
1630-
norm = Normalize(vmin=data.min(), vmax=data.max())
1642+
norm = Normalize(vmin=vmin, vmax=vmax)
16311643

16321644
rgb0 = cmap(norm(data))
16331645
rgb1 = self.shade_rgb(rgb0, elevation=data, blend_mode=blend_mode,

0 commit comments

Comments
 (0)