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

Skip to content

Lightsource enhancements #3291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
Sep 29, 2014
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
Updated shading example to show new styles and added exmaple DEM from…
… SRTM data
  • Loading branch information
joferkington committed Jul 22, 2014
commit ed5cd76d231a8279633bde02e6549350c005fa82
59 changes: 40 additions & 19 deletions examples/pylab_examples/shading_example.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,49 @@
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LightSource
from matplotlib import cbook

# example showing how to make shaded relief plots
# Example showing how to make shaded relief plots
# like Mathematica
# (http://reference.wolfram.com/mathematica/ref/ReliefPlot.html)
# or Generic Mapping Tools
# (http://gmt.soest.hawaii.edu/gmt/doc/gmt/html/GMT_Docs/node145.html)

# test data
X,Y=np.mgrid[-5:5:0.05,-5:5:0.05]
Z=np.sqrt(X**2+Y**2)+np.sin(X**2+Y**2)
# create light source object.
ls = LightSource(azdeg=0,altdeg=65)
# shade data, creating an rgb array.
rgb = ls.shade(Z,plt.cm.copper)
# plot un-shaded and shaded images.
plt.figure(figsize=(12,5))
plt.subplot(121)
plt.imshow(Z,cmap=plt.cm.copper)
plt.title('imshow')
plt.xticks([]); plt.yticks([])
plt.subplot(122)
plt.imshow(rgb)
plt.title('imshow with shading')
plt.xticks([]); plt.yticks([])
plt.show()
def main():
# Test data
x, y = np.mgrid[-5:5:0.05, -5:5:0.05]
z = 5 * (np.sqrt(x**2 + y**2) + np.sin(x**2 + y**2))
fig = compare(z, plt.cm.copper)
fig.suptitle('HSV Blending Looks Best with Smooth Surfaces', y=0.95)

dem = np.load(cbook.get_sample_data('jacksboro_fault_dem.npz'))
fig = compare(dem['elevation'], plt.cm.gist_earth, ve=0.05)
fig.suptitle('Overlay Blending Looks Best with Rough Surfaces', y=0.95)

plt.show()

def compare(z, cmap, ve=1):
# Create subplots and hide ticks
fig, axes = plt.subplots(ncols=2, nrows=2)
for ax in axes.flat:
ax.set(xticks=[], yticks=[])

# Illuminate the scene from the northwest
ls = LightSource(azdeg=315, altdeg=45)

axes[0,0].imshow(z, cmap=cmap)
axes[0,0].set(xlabel='Colormapped Data')

axes[0,1].imshow(ls.hillshade(z, vert_exag=ve), cmap='gray')
axes[0,1].set(xlabel='Illumination Intensity')

axes[1,0].imshow(ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='hsv'))
axes[1,0].set(xlabel='Blend Mode: "hsv" (default)')

axes[1,1].imshow(ls.shade(z, cmap=cmap, vert_exag=ve, blend_mode='overlay'))
axes[1,1].set(xlabel='Blend Mode: "overlay"')

return fig

if __name__ == '__main__':
main()
Binary file not shown.