Skip to content

WIP: Add offset normalizer #3858

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 8 commits into from
Closed

Conversation

phobson
Copy link
Member

@phobson phobson commented Nov 27, 2014

Trying to close #1806

Not currently on a good machine for development, but I think this pretty straight-forward, so hopefully Travis a test runner will suffice...

OffsetNorm: This let's you set vmin, vcenter, and vmax. The use case for this is when you have data ranging from e.g., -1, to +2, and you want the the white/gray part at 0, but would also like to use the full range of the red scale. So:

offset = mcolors.OffsetNorm(vmin=-1, vcenter=0, vmax=2)
offset([-1.0, -0.5, 0.0, 1.0, 2.,])

#prints
[0, 0.25, 0.5, 0.75, 1.0]

Next I'll add SymNorm, that will look at the absolute values of vmin and vmax to produce:

sym = mcolors.SymNorm(vmin=-1, vcenter=0, vmax=2)
sym([-1.0, -0.5, 0.0, 1.0, 2.,])

#prints
[0.25, 0.325, 0.5, 0.75, 1.0]

@phobson
Copy link
Member Author

phobson commented Nov 27, 2014

@tacaswell I based this off of a master that I pulled down last night. Is that ok?

@tacaswell
Copy link
Member

Yes

On Thu, Nov 27, 2014, 11:35 Paul Hobson notifications@github.com wrote:

@tacaswell https://github.com/tacaswell I based this off of a master
that I pulled down last night. Is that ok?


Reply to this email directly or view it on GitHub
#3858 (comment)
.

@phobson phobson force-pushed the add-asym-norm branch 2 times, most recently from 60aaec1 to 37ff5a5 Compare November 27, 2014 21:32
@Tillsten
Copy link
Contributor

You are right about my last comment, but i have still three points:
There is buggy behavior with all negative limits:

os = OffsetNorm(-5, -2, -1)
x = np.linspace(-6, 6, 100)
abs(x-os.inverse(os(x))).max()  #should be zero, but is two

This is why my stackoverflow answer (which you probably read before :)) divides by

 abs(vmax - midpoint) 
 abs(vmin - midpoint)

instead of vmax-vcenter.

Second point the class has no docstring.
Third is i don't think OffsetNorm is a very descriptive name, but the alternatives are also not
very good (MidpointNorm, CenteredNorm) .

@phobson
Copy link
Member Author

phobson commented Nov 28, 2014

Yeah. Good points all around. What you you think about BiasedNorm?

@tacaswell tacaswell added this to the v1.5.x milestone Nov 29, 2014
raise ValueError("Not invertible until scaled")

vmin = float(self.vmin)
vcenter = float(self.vcenter)
Copy link
Member

Choose a reason for hiding this comment

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

I think there is a code path that will end up with self.vcenter to be None? I think you need to also override autoscale_None to make sure it gets set.

Copy link
Member Author

Choose a reason for hiding this comment

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

@tacaswell yup. Got that written, Will default to half-way in the middle if not specified.

Thought about looking at the signs of vmax and vmin to see if 0 would be a good choice, but I think edge cases of -0.001 and 1000 make that more complicated than it means to be,

@tacaswell
Copy link
Member

Needs documentation and tests that stress the code a bit more.

@phobson
Copy link
Member Author

phobson commented Nov 30, 2014

Hey @Tillsten

I really feel like your class you posted on SO is more robust. I don't feel right using it here without you on the commit log. Do you want to pull this branch down and overwrite what I have with your class?

@phobson
Copy link
Member Author

phobson commented Nov 30, 2014

@tacaswell

About the tests, happy to beef things about a bit. What do you think about the pattern I'm using with subclassing a base test case? I feel like the whole file could benefit from similar treatment (separate PR,of course).

@phobson
Copy link
Member Author

phobson commented Nov 30, 2014

@Tillsten
Copy link
Contributor

@phobsen Just use it, i will hopefully get other commits anyway. If i ever find the free time ... :)

phobson referenced this pull request in phobson/matplotlib Dec 1, 2014
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`
phobson referenced this pull request in phobson/matplotlib Dec 1, 2014
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`
phobson referenced this pull request in phobson/matplotlib Dec 1, 2014
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`
self.vmax = vmax
self.clip = clip

def __call__(self, value, clip=False):
Copy link
Member

Choose a reason for hiding this comment

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

Should the default value be None ?

@tacaswell
Copy link
Member

This looks pretty solid. Left a few picky comments.

I am a bit confused by the decorators working on 2.6 and a bit concerned about the test classes as I don't recall seeing them anyplace else in the test suite.

@phobson
Copy link
Member Author

phobson commented Jun 15, 2015

I did. It didn't change anything, though I was working on a janky dev installation of MPL, so I should probably give it another shot.

Looking back a existing source code, LogNorm does have an inverse method, so there's something to learn there I'm sure.

@OceanWolf
Copy link
Member

Just had an idea in terms of a name for the general case, GraduatedNorm, what do you think?

@efiring
Copy link
Member

efiring commented Jun 30, 2015

It sounds like all this is actually about using a continuous piece-wise linear curve (first-degree spline) as the mapping function. Is that correct? GraduatedNorm doesn't give me any picture of what it is supposed to be.

@Tillsten
Copy link
Contributor

Tillsten commented Jul 1, 2015

PiecewiseLinearNorm sounds good to me.

@WeatherGod
Copy link
Member

I like that name.

On Tue, Jun 30, 2015 at 11:17 PM, Till Stensitzki notifications@github.com
wrote:

PiecewiseLinearNorm sounds good to me.


Reply to this email directly or view it on GitHub
#3858 (comment)
.

@OceanWolf
Copy link
Member

👍

@tacaswell
Copy link
Member

Closing in favor of #4666 @phobson ping to have this re-opened if you want to take over development again.

@tacaswell tacaswell closed this Jul 16, 2015
jkseppan referenced this pull request in jkseppan/matplotlib Sep 13, 2015
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`
OceanWolf referenced this pull request in OceanWolf/matplotlib Sep 14, 2015
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`
@phobson phobson deleted the add-asym-norm branch October 14, 2016 17:03
jklymak referenced this pull request in jklymak/matplotlib Oct 6, 2018
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`
jklymak referenced this pull request in jklymak/matplotlib Oct 6, 2018
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`
jklymak referenced this pull request in jklymak/matplotlib Oct 7, 2018
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`
jklymak referenced this pull request in jklymak/matplotlib Oct 7, 2018
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`
jklymak referenced this pull request in jklymak/matplotlib Oct 7, 2018
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`
jklymak referenced this pull request in jklymak/matplotlib Oct 7, 2018
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`
jklymak referenced this pull request in jklymak/matplotlib Oct 7, 2018
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`
jklymak referenced this pull request in jklymak/matplotlib Feb 5, 2019
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`

TST: add tests for DivergingNorm

DOC: add to colors_api.rst
jklymak referenced this pull request in jklymak/matplotlib Feb 6, 2019
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`

TST: add tests for DivergingNorm

DOC: add to colors_api.rst
jklymak referenced this pull request in jklymak/matplotlib Mar 7, 2019
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`

TST: add tests for DivergingNorm

DOC: add to colors_api.rst
jklymak referenced this pull request in jklymak/matplotlib Mar 8, 2019
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`

TST: add tests for DivergingNorm

DOC: add to colors_api.rst

DOC: add tutorial

FIX: fix extend=both
jklymak referenced this pull request in jklymak/matplotlib Mar 8, 2019
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`

TST: add tests for DivergingNorm

DOC: add to colors_api.rst

DOC: add tutorial

FIX: fix extend=both
jklymak referenced this pull request in jklymak/matplotlib Mar 13, 2019
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`

TST: add tests for DivergingNorm

DOC: add to colors_api.rst

DOC: add tutorial

FIX: fix extend=both

DOC: add new example
jklymak referenced this pull request in jklymak/matplotlib Mar 13, 2019
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`

TST: add tests for DivergingNorm

DOC: add to colors_api.rst

DOC: add tutorial

FIX: fix extend=both

DOC: add new example
jklymak referenced this pull request in jklymak/matplotlib Mar 14, 2019
Borrows heavily from @Tillsen's solution found on
StackOverflow here: http://goo.gl/RPXMYB

Used with his permission dicussesd on Github here:
https://github.com/matplotlib/matplotlib/pull/3858`

TST: add tests for DivergingNorm

DOC: add to colors_api.rst

DOC: add tutorial

FIX: fix extend=both

DOC: add new example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add symmetric norm for colormaps
7 participants