BUG: Ensure that distinct polygon collections are shaded identically#12792
Merged
timhoffm merged 3 commits intomatplotlib:masterfrom Jan 6, 2019
Merged
BUG: Ensure that distinct polygon collections are shaded identically#12792timhoffm merged 3 commits intomatplotlib:masterfrom
timhoffm merged 3 commits intomatplotlib:masterfrom
Conversation
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)
eric-wieser
commented
Nov 12, 2018
lib/mpl_toolkits/mplot3d/axes3d.py
Outdated
| # convert dot product to allowed shading fractions | ||
| in_norm = Normalize(-1, 1) | ||
| out_norm = Normalize(0.3, 1).inverse | ||
| norm = lambda x: out_norm(in_norm(x)) |
Contributor
Author
There was a problem hiding this comment.
0.3 was chosen to roughly give the same shading in the test-cases as before
dstansby
reviewed
Nov 14, 2018
lib/mpl_toolkits/mplot3d/axes3d.py
Outdated
| # convert dot product to allowed shading fractions | ||
| in_norm = Normalize(-1, 1) | ||
| out_norm = Normalize(0.3, 1).inverse | ||
| norm = lambda x: out_norm(in_norm(x)) |
Member
There was a problem hiding this comment.
PEP 8 doesn't like assigning a variable to a lambda. I'm kind of indifferent but I guess it would be possible to do
def norm(x):
return out_norm(in_norm(x))
Contributor
Author
There was a problem hiding this comment.
Has the extra requirement that it needs blank lines around it, which IMO makes the grouping less clear.
I guess I'll just drop the lambda, and substitute out_norm(in_norm(x)) at the call site.
Contributor
Author
|
@dstansby: PEP8 issues fixed |
anntzer
approved these changes
Dec 19, 2018
timhoffm
approved these changes
Jan 6, 2019
6 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
PR Summary
PR Checklist