Skip to content
Merged
Changes from all commits
Commits
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
27 changes: 18 additions & 9 deletions lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,14 @@ def gray_from_float_rgba():
def test_light_source_topo_surface():
"""Shades a DEM using different v.e.'s and blend modes."""
fname = cbook.get_sample_data('jacksboro_fault_dem.npz', asfileobj=False)
with np.load(fname) as dem:
elev = dem['elevation']
# Get the true cellsize in meters for accurate vertical exaggeration
# Convert from decimal degrees to meters
dx, dy = dem['dx'], dem['dy']
dx = 111320.0 * dx * np.cos(dem['ymin'])
dy = 111320.0 * dy
dem = np.load(fname)
elev = dem['elevation']
# Get the true cellsize in meters for accurate vertical exaggeration
# Convert from decimal degrees to meters
dx, dy = dem['dx'], dem['dy']
dx = 111320.0 * dx * np.cos(dem['ymin'])
dy = 111320.0 * dy
dem.close()

ls = mcolors.LightSource(315, 45)
cmap = cm.gist_earth
Expand Down Expand Up @@ -307,7 +308,8 @@ def test_light_source_shading_default():
assert_array_almost_equal(rgb, expect, decimal=2)


@knownfailureif(V(np.__version__) >= V('1.9.0'))
@knownfailureif(V(np.__version__) >= V('1.9.0') or
V(np.__version__) < V('1.7.0'))
def test_light_source_masked_shading():
"""Array comparison test for a surface with a masked portion. Ensures that
we don't wind up with "fringes" of odd colors around masked regions."""
Expand Down Expand Up @@ -371,7 +373,14 @@ def alternative_hillshade(azimuth, elev, z):
dy = -dy
dz = np.ones_like(dy)
normals = np.dstack([dx, dy, dz])
normals /= np.linalg.norm(normals, axis=2)[..., None]
dividers = np.zeros_like(z)[..., None]
for i, mat in enumerate(normals):
for j, vec in enumerate(mat):
dividers[i, j, 0] = np.linalg.norm(vec)
normals /= dividers
# once we drop support for numpy 1.7.x the above can be written as
# normals /= np.linalg.norm(normals, axis=2)[..., None]
# aviding the double loop.

intensity = np.tensordot(normals, illum, axes=(2, 0))
intensity -= intensity.min()
Expand Down