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

Skip to content
Merged
Changes from 1 commit
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
Next Next commit
BUG: Respect the lightsource argument in plot_surface and plot_trisurf
  • Loading branch information
eric-wieser committed Jul 12, 2018
commit 833543dc97746dc03d633105419e133bd9141069
13 changes: 8 additions & 5 deletions lib/mpl_toolkits/mplot3d/axes3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -1688,7 +1688,7 @@ def get_normals(polygons):

if fcolors is not None:
if shade:
colset = self._shade_colors(colset, get_normals(polys))
colset = self._shade_colors(colset, get_normals(polys), lightsource)
polyc.set_facecolors(colset)
polyc.set_edgecolors(colset)
elif cmap:
Expand All @@ -1701,7 +1701,7 @@ def get_normals(polygons):
polyc.set_norm(norm)
else:
if shade:
colset = self._shade_colors(color, get_normals(polys))
colset = self._shade_colors(color, get_normals(polys), lightsource)
else:
colset = color
polyc.set_facecolors(colset)
Expand All @@ -1725,13 +1725,16 @@ def _generate_normals(self, polygons):
normals.append(np.cross(v1, v2))
return normals

def _shade_colors(self, color, normals):
def _shade_colors(self, color, normals, lightsource=None):
'''
Shade *color* using normal vectors given by *normals*.
*color* can also be an array of the same length as *normals*.
'''
if lightsource is None:
# chosen for backwards-compatibility
lightsource = LightSource(azdeg=225, altdeg=19.4712)

shade = np.array([np.dot(n / proj3d.mod(n), [-1, -1, 0.5])
shade = np.array([np.dot(n / proj3d.mod(n), lightsource.direction)
if proj3d.mod(n) else np.nan
for n in normals])
mask = ~np.isnan(shade)
Expand Down Expand Up @@ -1965,7 +1968,7 @@ def plot_trisurf(self, *args, color=None, norm=None, vmin=None, vmax=None,
v1 = verts[:, 0, :] - verts[:, 1, :]
v2 = verts[:, 1, :] - verts[:, 2, :]
normals = np.cross(v1, v2)
colset = self._shade_colors(color, normals)
colset = self._shade_colors(color, normals, lightsource)
else:
colset = color
polyc.set_facecolors(colset)
Expand Down