Skip to content
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

WIP: Add offset normalizer #3858

Closed
wants to merge 8 commits into from
Closed

Conversation

@phobson
Copy link
Member

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Member

tacaswell commented Nov 27, 2014

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 phobson:add-asym-norm branch 2 times, most recently from 60aaec1 to 37ff5a5 Nov 27, 2014
@Tillsten

This comment has been minimized.

Copy link
Contributor

Tillsten commented Nov 28, 2014

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

This comment has been minimized.

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)

This comment has been minimized.

Copy link
@tacaswell

tacaswell Nov 29, 2014

Member

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.

This comment has been minimized.

Copy link
@phobson

phobson Nov 30, 2014

Author Member

@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,



class SymmetricalNorm(Normalize):
def __init__(self, vmin=None, vmax=None, clip=False):

This comment has been minimized.

Copy link
@tacaswell

tacaswell Nov 29, 2014

Member

I am not really a fan of this class. It will also behave in very strange ways for vmin/vmax of the same sign.

@tacaswell

This comment has been minimized.

Copy link
Member

tacaswell commented Nov 29, 2014

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

@phobson

This comment has been minimized.

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

This comment has been minimized.

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

This comment has been minimized.

@Tillsten

This comment has been minimized.

Copy link
Contributor

Tillsten commented Nov 30, 2014

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

@phobson phobson force-pushed the phobson:add-asym-norm branch from 2d41664 to 933626c Dec 1, 2014
phobson added a commit to phobson/matplotlib that referenced this pull request 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:
matplotlib#3858
@phobson phobson force-pushed the phobson:add-asym-norm branch from 933626c to 0b17fcf Dec 1, 2014
phobson added a commit to phobson/matplotlib that referenced this pull request 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:
matplotlib#3858
@phobson phobson force-pushed the phobson:add-asym-norm branch from 0b17fcf to 205e8b9 Dec 1, 2014
phobson added a commit to phobson/matplotlib that referenced this pull request 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:
matplotlib#3858
self.vmax = vmax
self.clip = clip

def __call__(self, value, clip=False):

This comment has been minimized.

Copy link
@tacaswell

tacaswell Dec 12, 2014

Member

Should the default value be None ?

if self.vcenter is None:
self.vcenter = (self.vmax + self.vmin) * 0.5

return None

This comment has been minimized.

Copy link
@tacaswell

tacaswell Dec 12, 2014

Member

Don't need the return

def setup(self):
self.vals = np.arange(50)

@nt.raises(ValueError)

This comment has been minimized.

Copy link
@tacaswell

tacaswell Dec 12, 2014

Member

How are these passing on 2.6? I thought the decorator-style raise tests are not available until 2.7... nm, I was confused

@tacaswell

This comment has been minimized.

Copy link
Member

tacaswell commented Dec 12, 2014

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

OceanWolf commented Jun 30, 2015

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

@efiring

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor

Tillsten commented Jul 1, 2015

PiecewiseLinearNorm sounds good to me.

@WeatherGod

This comment has been minimized.

Copy link
Member

WeatherGod commented Jul 1, 2015

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

This comment has been minimized.

Copy link
Contributor

OceanWolf commented Jul 1, 2015

👍

@tacaswell

This comment has been minimized.

Copy link
Member

tacaswell commented Jul 16, 2015

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
@tacaswell tacaswell removed the Needs review label Jul 16, 2015
jkseppan added a commit to jkseppan/matplotlib that referenced this pull request 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:
matplotlib#3858
OceanWolf added a commit to OceanWolf/matplotlib that referenced this pull request 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:
matplotlib#3858
@phobson phobson deleted the phobson:add-asym-norm branch Oct 14, 2016
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858
@jklymak jklymak mentioned this pull request Oct 6, 2018
3 of 6 tasks complete
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858

TST: add tests for DivergingNorm

DOC: add to colors_api.rst
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858

TST: add tests for DivergingNorm

DOC: add to colors_api.rst
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858

TST: add tests for DivergingNorm

DOC: add to colors_api.rst
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858

TST: add tests for DivergingNorm

DOC: add to colors_api.rst

DOC: add tutorial

FIX: fix extend=both
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858

TST: add tests for DivergingNorm

DOC: add to colors_api.rst

DOC: add tutorial

FIX: fix extend=both
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858

TST: add tests for DivergingNorm

DOC: add to colors_api.rst

DOC: add tutorial

FIX: fix extend=both

DOC: add new example
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#3858

TST: add tests for DivergingNorm

DOC: add to colors_api.rst

DOC: add tutorial

FIX: fix extend=both

DOC: add new example
jklymak added a commit to jklymak/matplotlib that referenced this pull request 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:
matplotlib#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
Projects
None yet
7 participants
You can’t perform that action at this time.