Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

ENH: Added FuncNorm and PiecewiseNorm classes in colors #7294

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
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2d90c5a
Added ArbitaryNorm and RootNorm classes in colors, as well as example…
Oct 17, 2016
57aad3d
PEP8 formatting on examples, plotting using the object oriented appro…
Oct 18, 2016
f818aff
Added title/description to the examples
Oct 18, 2016
ffe1b9d
Class attributes are now hidden
Oct 18, 2016
1d22b90
Major update: complete refactorization of code. A much more powerful …
Oct 19, 2016
b5801ea
Corrected lambda function syntax that was not compatible with python …
Oct 19, 2016
e93d82d
Added FuncNorm: now everything inherits from this. Changed the name o…
Oct 20, 2016
3749b0a
Forgot to uncomment an import
Oct 20, 2016
de62491
Improved the auto-tick feature, and corrected some pep8 issues
Oct 20, 2016
d148756
Improved examples, created a new file for generating sample data.'
alvarosg Oct 22, 2016
5373a98
Corrected a double line, and removed a comment
alvarosg Oct 22, 2016
13edeab
Tests for FuncNorm added, and bug corrected in FuncNorm
alvarosg Oct 22, 2016
21d5cd0
Added compatibility for python 3 string check, added tests for Piecew…
alvarosg Oct 22, 2016
d359a4e
Added tests on all classes, including all public methods
alvarosg Oct 22, 2016
4622829
Change type of arrays in tests from int to float
alvarosg Oct 22, 2016
30ff404
Corrected wrong `super()` for RootNorm
alvarosg Oct 22, 2016
df835cb
Solve problem with implicit int to float casting that was not working…
alvarosg Oct 22, 2016
dfaa0f8
Added documentation in the numpydoc format
alvarosg Oct 23, 2016
a386395
Improve style in the examples. Corrected intending problem in the doc…
alvarosg Oct 23, 2016
b9dafb0
Added example in `FuncNorm` docstring
alvarosg Oct 23, 2016
d10be73
Finished with the examples in the docstrings
alvarosg Oct 24, 2016
c85a14c
Implemented clipping behavoir. Refactored _func_parser
alvarosg Oct 26, 2016
7597ddd
It now allows some string functions with parameters. Added a test for…
alvarosg Oct 28, 2016
7fce503
Forgot to add a file...
alvarosg Oct 28, 2016
bcd7dd0
Forgot to add another file...
alvarosg Oct 28, 2016
a71e1e9
Improved tests, documentation, and exceptions
alvarosg Oct 31, 2016
33f57d1
Removed test_colors.py from __init__.py after including parametrize
alvarosg Oct 31, 2016
9687173
Moved the string function parser to its own class in cbook. Added tes…
alvarosg Nov 1, 2016
46395aa
Improved documentation
Nov 2, 2016
63dab61
Added new example
Nov 2, 2016
8abf2c2
Added example for PiecewiseNorm, and MirrorPiecewiseNorm. String in t…
alvarosg Nov 3, 2016
b4ecdb2
Removed sampledata.py no longer necessary, and changed examples in do…
alvarosg Nov 3, 2016
42007ee
Added examples for MirrorRootNorm and RootNorm
alvarosg Nov 3, 2016
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
Prev Previous commit
Next Next commit
Tests for FuncNorm added, and bug corrected in FuncNorm
  • Loading branch information
alvarosg committed Oct 23, 2016
commit 13edeabea7979c7bf619272c0ce3f83e9b718e69
3 changes: 1 addition & 2 deletions 3 lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,7 +964,6 @@ def __init__(self, f, finv=None,
vmin=None, vmax=None, clip=False):

f, finv = FuncNorm._fun_parser([f, finv])

if finv is None:
raise ValueError("Inverse function not provided")

Expand All @@ -985,6 +984,7 @@ def __call__(self, value, clip=None):
clip = self.clip

result, is_scalar = self.process_value(value)
self.autoscale_None(result)

vmin = self.vmin
vmax = self.vmax
Expand All @@ -996,7 +996,6 @@ def __call__(self, value, clip=None):
resultnorm = (self._f(result) - self._f(vmin)) / \
(self._f(vmax) - self._f(vmin))

self.autoscale_None(resultnorm)
return np.ma.array(resultnorm)

def inverse(self, value):
Expand Down
18 changes: 18 additions & 0 deletions 18 lib/matplotlib/tests/test_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,24 @@ def test_LogNorm():
ln = mcolors.LogNorm(clip=True, vmax=5)
assert_array_equal(ln([1, 6]), [0, 1.0])

def test_FuncNorm():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should probably either be broken into separate tests or parameterized cause if one of the tests fails, it would likely require going back to the source to figure which subcategories failed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess the line of the assert is always shown, but in any case, could you show me an example of parameterized, please?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But assert doesn't spit error messages, so you're kind of left guessing what specific thing that assert was trying to test.
http://doc.pytest.org/en/latest/parametrize.html and test_category.py has lots of mpl examples.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have now included a test class for each of the implemented classes, and each assert in a separate name method. It also includes a parametric test to replace the loop I had before.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, the parametric test is not working, for some reason. Do you know, if apart from using the decorator, I have to do anything else? All other tests in the file are single method very basic tests (which is why I did it like that originally)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @QuLogic, it should build now!

# Testing limits using a string
norm = mcolors.FuncNorm(f='log', vmin=0.01, vmax=2)
assert_array_equal(norm([0.01, 2]), [0, 1.0])

# Testing limits using a string
norm = mcolors.FuncNorm(f=lambda x: np.log10(x),
finv=lambda x: 10.**(x), vmin=0.01, vmax=2)
assert_array_equal(norm([0.01, 2]), [0, 1.0])

# Testing limits without vmin, vmax
norm = mcolors.FuncNorm(f='log')
assert_array_equal(norm([0.01, 2]), [0, 1.0])

# Testing intermediate values
norm = mcolors.FuncNorm(f='log')
assert_array_almost_equal(norm([0.01, 0.5, 2]), [0, 0.73835195870437, 1.0])


def test_PowerNorm():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:) that you broke up the above tests, wanna see these tests broken up too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean by "these"? I guess for now I would only like to change the tests related to the new functionality. Maybe we can have a separate PR later for refactoring all tests test_colors.py.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, sorry, didn't realize PowerNorm wasn't one of yours.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, I do not blame you, it could perfectly be. In fact I have been tempted to re-implement it inheriting from PiecewiseNorm (It would not inherit from FuncNorm due to a difference in the normalization policy that @anntzer mentioned. (FuncNorm does the "LogNorm" way, because it is a rawer function, and PiecewiseNorm does it the "PowerNorm" way, because it really wants to ensure that the normalization function for each interval is bounded).

Again, my view on this would be to first merge the new classes, and give it a round of tests, and then maybe consider re-implementing other classes to make them inherit from these.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine by me.

a = np.array([0, 0.5, 1, 1.5], dtype=float)
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.