-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
2D Normalization & Colormapping for ScalerMappables #8738
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
Changes from 1 commit
201dc2a
7217536
0178730
575a244
8425637
4a5831d
85df736
8e1bc63
a9aace3
55a7a68
c2eb617
daef751
96af3d3
9285372
01b5932
28288e2
ca2b111
75b4eba
bf65847
f9dc4b1
8a985f0
8f6928d
d54cb44
4d03552
2573610
9228480
5c8dc65
21ea65f
b8d43a9
7681d14
59f56af
f98978f
75a289f
7803974
e40c87b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5146,8 +5146,7 @@ def imshow(self, X, cmap=None, norm=None, aspect=None, | |
| if not self._hold: | ||
| self.cla() | ||
|
|
||
| isNorm = isinstance(norm, (mcolors.Normalize, mcolors.BivariateNorm)) | ||
| if norm is not None and not isNorm: | ||
| if norm is not None and not isinstance(norm, mcolors.Norms): | ||
| msg = "'norm' must be an instance of 'mcolors.Normalize' " \ | ||
| "or 'mcolors.BivariateNorm'" | ||
| raise ValueError(msg) | ||
|
|
@@ -5483,8 +5482,7 @@ def pcolor(self, *args, **kwargs): | |
| collection.set_alpha(alpha) | ||
| collection.set_array(C) | ||
|
|
||
| isNorm = isinstance(norm, (mcolors.Normalize, mcolors.BivariateNorm)) | ||
| if norm is not None and not isNorm: | ||
| if norm is not None and not isinstance(norm, mcolors.Norms): | ||
| msg = "'norm' must be an instance of 'mcolors.Normalize' " \ | ||
|
Member
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. We have a style preference for using msg = ('...' +
'...')
Contributor
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. The + is not needed.
Contributor
Author
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. Done. |
||
| "or 'mcolors.BivariateNorm'" | ||
| raise ValueError(msg) | ||
|
|
@@ -5764,8 +5762,8 @@ def pcolorfast(self, *args, **kwargs): | |
| cmap = kwargs.pop('cmap', None) | ||
| vmin = kwargs.pop('vmin', None) | ||
| vmax = kwargs.pop('vmax', None) | ||
| isNorm = isinstance(norm, (mcolors.Normalize, mcolors.BivariateNorm)) | ||
| if norm is not None and not isNorm: | ||
|
|
||
| if norm is not None and not isinstance(norm, mcolors.Norms): | ||
| msg = "'norm' must be an instance of 'mcolors.Normalize' " \ | ||
| "or 'mcolors.BivariateNorm'" | ||
| raise ValueError(msg) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -68,7 +68,7 @@ | |
| import numpy as np | ||
| import matplotlib.cbook as cbook | ||
| from ._color_data import BASE_COLORS, TABLEAU_COLORS, CSS4_COLORS, XKCD_COLORS | ||
|
|
||
| from abc import ABCMeta | ||
|
|
||
| class _ColorMapping(dict): | ||
| def __init__(self, mapping): | ||
|
|
@@ -885,7 +885,14 @@ def reversed(self, name=None): | |
| raise NotImplementedError() | ||
|
Contributor
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. No need for the parentheses.
Contributor
Author
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. Done. |
||
|
|
||
|
|
||
| class Normalize(object): | ||
| class Norms: | ||
| """ | ||
| Abstract Base Class to group `Normalize` and `BivariateNorm` | ||
| """ | ||
| __metaclass__ = ABCMeta | ||
|
Contributor
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. definitely wrong on Py3
Contributor
Author
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. Fixed now. |
||
| pass | ||
|
|
||
| class Normalize(Norms): | ||
| """ | ||
| A class which, when called, can normalize data into | ||
| the ``[0.0, 1.0]`` interval. | ||
|
|
@@ -1377,7 +1384,7 @@ def inverse(self, value): | |
| return value | ||
|
|
||
|
|
||
| class BivariateNorm: | ||
| class BivariateNorm(Norms): | ||
| """ | ||
| Normalize a list of two values corresponding to two 1D normalizers | ||
| """ | ||
|
|
||
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.
shouldn't
BivariateNormsubclass Normalize? 'specially since now it's normalizing down to a 1d space?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.
BivariateNorm does not inherit anything from Normalize so I thought it should not subclass it.
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.
With the new design, BivariateNorm should havel all the same classes as Normalize...and I think subclassing it so it's registered generically as a Norm is preferable to having to treat it as a special case when it doesn't need to be.
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.
This can be done with an
ABChttps://docs.python.org/3/library/abc.html#abc.ABCMeta.register which both Normalize and BivariateNorm register with.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.
Sure, but I don't see a reason why BivariateNorm shouldn't be subclassing Norm as it has the same architecture as any other norm...take data (scaler or vector)->map to 1D lut value ->get color, and color ->lut->scaler/vector.
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.
If the code paths are completely different, why force the sub-class? In general, sub-classing is only worth it when you can share significant amounts of implementation details, otherwise duck-typing is better.
Uh oh!
There was an error while loading. Please reload this page.
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.
My point is mostly that the code paths shouldn't end up being all that different and more to the point in mpl land there's probably a ton of code that checks if things are norms and if this code works in those instances it doesn't make sense to change all that code to cover both cases when this is still fundamentally a norm. But I think I'm on the same page as you on the solution maybe being a "Norm" metaclass.