Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
ee99cf5
Refactored LightSource.shade_rgb into three separate functions
joferkington Jul 21, 2014
4faa454
Added support for vertical exag and non-uniform spacing to LightSource
joferkington Jul 21, 2014
a1af495
Added new blending modes to LightSource for more realistic rendering
joferkington Jul 21, 2014
ed5cd76
Updated shading example to show new styles and added exmaple DEM from…
joferkington Jul 22, 2014
0db6341
Make the "fraction" kwarg behave as it did before recent LightSource …
joferkington Jul 23, 2014
52434ff
Strip whitespace and strict PEP8 compliance
joferkington Jul 23, 2014
108eac7
Avoid potential divide by zero in LightSource.hillshade
joferkington Jul 23, 2014
f374383
Fix calculation of aspect for hillshading.
joferkington Jul 25, 2014
3c9cacf
Make clipping work properly for effectively planar surfaces
joferkington Jul 25, 2014
51e9a6c
Added tests for LightSource functionality
joferkington Jul 26, 2014
31a4239
Added example of using the custom hillshading on a 3D surface plot
joferkington Jul 26, 2014
b3e2e3d
PEP8 fixes
joferkington Jul 26, 2014
bdbc7df
Avoid leaking file descriptors in tests and examples
joferkington Jul 26, 2014
71cb786
Added more examples
joferkington Sep 26, 2014
4afed00
Fixed hillshading problems with masked elevation arrays
joferkington Sep 27, 2014
abf8b87
Added array comparison tests for shaded relief
joferkington Sep 27, 2014
ba1f492
Strict PEP8 compliance for printed arrays
joferkington Sep 27, 2014
ab40a2f
Added *vmin* and *vmax* arguments to LightSource.shade
joferkington Sep 27, 2014
9fce26c
Added LightSource changes summary to CHANGELOG
joferkington Sep 27, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added *vmin* and *vmax* arguments to LightSource.shade
  • Loading branch information
joferkington committed Sep 28, 2014
commit ab40a2f2de9cfff9f48fdde7b62a29cdebc197b7
2 changes: 1 addition & 1 deletion examples/specialty_plots/advanced_hillshading.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def avoid_outliers():
ax1.imshow(rgb)
ax1.set_title('Full range of data')

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

Expand Down
18 changes: 15 additions & 3 deletions lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1574,8 +1574,8 @@ 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',
vert_exag=1, dx=1, dy=1, fraction=1, **kwargs):
def shade(self, data, cmap, norm=None, blend_mode='hsv', vmin=None,
vmax=None, vert_exag=1, dx=1, dy=1, fraction=1, **kwargs):
"""
Combine colormapped data values with an illumination intensity map
(a.k.a. "hillshade") of the values.
Expand Down Expand Up @@ -1603,6 +1603,14 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv',
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
argument will be ignored.
vmax : scalar or None, optional
The maximum value used in colormapping *data*. If *None* the
maximum value in *data* is used. If *norm* is specified, then this
argument will be ignored.
vert_exag : number, optional
The amount to exaggerate the elevation values by when calculating
illumination. This can be used either to correct for differences in
Expand All @@ -1626,8 +1634,12 @@ def shade(self, data, cmap, norm=None, blend_mode='hsv',
rgba : ndarray
An MxNx4 array of floats ranging between 0-1.
"""
if vmin is None:
vmin = data.min()
if vmax is None:
vmax = data.max()
if norm is None:
norm = Normalize(vmin=data.min(), vmax=data.max())
norm = Normalize(vmin=vmin, vmax=vmax)

rgb0 = cmap(norm(data))
rgb1 = self.shade_rgb(rgb0, elevation=data, blend_mode=blend_mode,
Expand Down