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

Skip to content

Commit 4897ffe

Browse files
eric-wiesertimhoffm
authored andcommitted
BUG: Ensure that distinct polygon collections are shaded identically (#12792)
* BUG: Ensure that distinct polygon collections are shaded identically Right now, shading ratios are computed by computing a shade in [-1, 1] for each face from the normal vector, and then normalizing across the polygon collection so that the brightest face has shade=1, and the dimmest shade=0.5. This behaves poorly with multiple polygon collections, as the normalization is internal to each. This results in two polygons with the same orientation but in different collections ending up with different shadings. Notably, this obstructs the shading of `ax.voxels()`. This approach instead scales `[-1, 1]` to `[0.4, 1]`, ignoring the local brightness minima and maxima within a collection. Some more noticeable effects of this change: * Highlights will be darker, unless they were already directly facing the light source * Contrast between extreme highlights and shadows will be slightly greater (from 1:0.5 to 1:0.4) * fixup: Resolve PEP8 complaints
1 parent 465f51a commit 4897ffe

File tree

6 files changed

+10
-3
lines changed

6 files changed

+10
-3
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,14 +1774,21 @@ def _shade_colors(self, color, normals, lightsource=None):
17741774
mask = ~np.isnan(shade)
17751775

17761776
if mask.any():
1777-
norm = Normalize(min(shade[mask]), max(shade[mask]))
1778-
shade[~mask] = min(shade[mask])
1777+
# convert dot product to allowed shading fractions
1778+
in_norm = Normalize(-1, 1)
1779+
out_norm = Normalize(0.3, 1).inverse
1780+
1781+
def norm(x):
1782+
return out_norm(in_norm(x))
1783+
1784+
shade[~mask] = 0
1785+
17791786
color = mcolors.to_rgba_array(color)
17801787
# shape of color should be (M, 4) (where M is number of faces)
17811788
# shape of shade should be (M,)
17821789
# colors should have final shape of (M, 4)
17831790
alpha = color[:, 3]
1784-
colors = (0.5 + norm(shade)[:, np.newaxis] * 0.5) * color
1791+
colors = norm(shade)[:, np.newaxis] * color
17851792
colors[:, 3] = alpha
17861793
else:
17871794
colors = np.asanyarray(color).copy()
Binary file not shown.

0 commit comments

Comments
 (0)