-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Re-write sym-log-norm #16391
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
Closed
Closed
Re-write sym-log-norm #16391
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
73ae1d3
Re-write sym-log-norm
dstansby 943a848
Allow specifying base
dstansby 60f0d69
Disallow vmin!=vmax
dstansby 6fdd2e0
Update tests
dstansby cc1fa93
Add base docs
dstansby 8904654
Add API change
dstansby 3fb1dcf
Check a different base
dstansby 82052d8
Fix color test
dstansby File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,22 +395,48 @@ def test_TwoSlopeNorm_premature_scaling(): | |
|
||
|
||
def test_SymLogNorm(): | ||
""" | ||
Test SymLogNorm behavior | ||
""" | ||
norm = mcolors.SymLogNorm(3, vmax=5, linscale=1.2) | ||
# Test SymLogNorm behavior | ||
norm = mcolors.SymLogNorm(linthresh=3, vmax=5, linscale=1.2, base=np.e) | ||
vals = np.array([-30, -1, 2, 6], dtype=float) | ||
normed_vals = norm(vals) | ||
expected = [0., 0.53980074, 0.826991, 1.02758204] | ||
expected = [-0.842119, 0.450236, 0.599528, 1.277676] | ||
assert_array_almost_equal(normed_vals, expected) | ||
_inverse_tester(norm, vals) | ||
_scalar_tester(norm, vals) | ||
_mask_tester(norm, vals) | ||
|
||
# Ensure that specifying vmin returns the same result as above | ||
norm = mcolors.SymLogNorm(3, vmin=-30, vmax=5, linscale=1.2) | ||
|
||
def test_symlognorm_vals(): | ||
vals = [-10, -1, 0, 1, 10] | ||
|
||
norm = mcolors.SymLogNorm(linthresh=1, vmin=-10, vmax=10, linscale=1) | ||
normed_vals = norm(vals) | ||
assert_array_almost_equal(normed_vals, expected) | ||
expected = [0, 0.25, 0.5, 0.75, 1] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is consistent with import matplotlib.scale as mscale
trans = mscale.SymmetricalLogTransform(10, 1, 1)
new = trans.transform([-10, -1, 0, 1, 10])
new = (new - new[0]) / (new[-1] - new[0])
print(new)
I'm fine if this implementation is desired, but then we need to change |
||
assert_array_almost_equal(norm(vals), normed_vals) | ||
assert_array_almost_equal(norm.inverse(norm(vals)), vals) | ||
|
||
# If we increase linscale to 2, the space for the linear range [0, 1] | ||
# should be twice as large as the space for the logarithmic range [1, 10] | ||
norm = mcolors.SymLogNorm(linthresh=1, vmin=-10, vmax=10, linscale=2) | ||
normed_vals = norm(vals) | ||
expected = [0, 1/6, 0.5, 5/6, 1] | ||
assert_array_almost_equal(norm(vals), normed_vals) | ||
assert_array_almost_equal(norm.inverse(norm(vals)), vals) | ||
|
||
# Similarly, going the other way means the linear range should shrink | ||
norm = mcolors.SymLogNorm(linthresh=1, vmin=-10, vmax=10, linscale=0.5) | ||
normed_vals = norm(vals) | ||
expected = [0, 2/6, 0.5, 4/6, 1] | ||
assert_array_almost_equal(norm(vals), normed_vals) | ||
assert_array_almost_equal(norm.inverse(norm(vals)), vals) | ||
|
||
# Now check a different base to base 10 | ||
vals = [-8, 4, -2, 0, 2, 4, 8] | ||
norm = mcolors.SymLogNorm(linthresh=2, vmax=8, linscale=1, base=2) | ||
normed_vals = norm(vals) | ||
expected = [0, 1/8, 2/8, 3/8, 0.5, 5/8, 6/8, 7/8, 1] | ||
assert_array_almost_equal(norm(vals), normed_vals) | ||
assert_array_almost_equal(norm.inverse(norm(vals)), vals) | ||
|
||
|
||
def test_SymLogNorm_colorbar(): | ||
|
@@ -907,7 +933,7 @@ def __add__(self, other): | |
for norm in [mcolors.Normalize(), mcolors.LogNorm(), | ||
mcolors.SymLogNorm(3, vmax=5, linscale=1), | ||
mcolors.Normalize(vmin=mydata.min(), vmax=mydata.max()), | ||
mcolors.SymLogNorm(3, vmin=mydata.min(), vmax=mydata.max()), | ||
mcolors.SymLogNorm(3, vmin=-10, vmax=10), | ||
mcolors.PowerNorm(1)]: | ||
assert_array_equal(norm(mydata), norm(data)) | ||
fig, ax = plt.subplots() | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these values were just plain wrong before...
vmax
(5), so should come out as less than zero