You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We have a PowerNorm. We should define a PowerScale derived from a PowerTransform consistent with the log norm, etc. This will allow a proper scale for PowerNorm. I'm not exactly sure what such a scale should look like (i.e. where to put the ticks), but its probably not a linear scale.
I'll mark as "Good first issue" because I think the example of LogNorm is relatively easy to follow and emulate down the stack. There is a bit of work to argue for the correct Locator and Formatter of the scale, but there must be examples out there.
just before the PowerNorm() class in the colors.py, it means I should access the kwargs for the PowerScale() in the scale.py file, am I right ?
Because I am trying to use them but in visual studio it says for example for vmin that "vmin" is not defined.
In the current implementation of make_norm_from_scale the value, vmin, and vmax are normalized after transformation as: f(value) - f(v_min) / (f(v_max) - f(v_min)).
However in case of PowerNorm, the expected behavior is normalizing before transformation as: f((value - vmin) / (vmax - vmin)).
One possible solution, is to add an optional boolean argument to make_norm_from_scale that changes the order in which transformation and normalization is applied (for example, norm_before_trf).
Yes, it is equivalent to ((a - vmin) / (vmax - vmin))**gamma, so a plain Normalize is the case of gamma=1. This seems reasonable to me; we are not dealing with logs. It is consistent with the description of Gamma correction: https://en.wikipedia.org/wiki/Gamma_correction. First the data are linearly scaled to the 0-1 range based on specified vmin and vmax, and second, that 0-1 range is mapped to a new 0-1 range by raising it to a power.
It seems that, doing normalization before transformation: ((a - vmin) / (vmax - vmin))**gamma is how PowerNorm is defined / expected to function.
If normalization is done after transformation (like other norms), the formula changes to (a**gamma - vmin**gamma)/(vmax**gamma - vmin**gamma).
Hi! I'm interested in working on this issue. I'm new to open source contributions but have been learning Python and would like to add the scale parameter to PowerNorm to make it consistent with other normalizers.
Based on the discussion, it looks like I need to:
Add a scale parameter to PowerNorm's init method
Apply the scaling in the normalization logic
Add appropriate tests
Is anyone else currently working on this? If not, I'd like to give it a try!
The implementation adds a scale parameter to PowerNorm that allows pre-scaling of input data before normalization. It maintains full backward compatibility (scale defaults to 1.0) and includes comprehensive tests.
I see the mypy-stubtest is failing because the type stub file needs to be updated to include the new scale parameter. Should I update lib/matplotlib/colors.pyi to add the scale parameter to the PowerNorm __init__ signature, or would you prefer to handle this differently?
Activity
jklymak commentedon Jun 3, 2021
I'll mark as "Good first issue" because I think the example of LogNorm is relatively easy to follow and emulate down the stack. There is a bit of work to argue for the correct Locator and Formatter of the scale, but there must be examples out there.
3r3n-n commentedon Jun 9, 2021
Hi !
Can I try to work on this ?
anntzer commentedon Jun 9, 2021
See the discussion at #10234, #7294 (comment), #12665 regarding PowerNorm's semantics, though.
yacth commentedon Jun 12, 2021
Hi @jklymak,
Could you tell me more about where should I start, which files are involved in here ?
I am willing to help for this issue.
jklymak commentedon Jun 12, 2021
colors.pyand look at how LogNorm is constructed...yacth commentedon Jun 13, 2021
Hi @jklymak could you explain me what this line does please ?
@_make_norm_from_scale(functools.partial(scale.LogScale, nonpositive="mask"))jklymak commentedon Jun 13, 2021
It makes the norm! Note
nonpositiveis a kwarg forLogScale. Thefunctools.partialpassesnonpsoitive="mask"to the init of the LogScale.I actually don't know why @anntzer used
functors.partialhere rather than passing the init kwarg.anntzer commentedon Jun 13, 2021
I don't really remember, bu I guess that may be because using the
initkwarg would have madenonpositivea kwarg toLogNorm, which it wasn't before?yacth commentedon Jun 13, 2021
Ok I understand, thank you.
Thus we have to add the 'PowerScale' in 'scale.py' I believe ?
How should we define it ? @jklymak, you said that there must be an example out here.
jklymak commentedon Jun 13, 2021
Again, trace what happens with LogScale...
yacth commentedon Jun 14, 2021
Hi @jklymak, I started the implementation in the
scale.pyfile of :PowerTransform: --> How we should define the distinctions for thebase? It seems that all bases could be fine with thisTransform.InvertedPowerTransform--> 100% done, it was similar to theInvertedLogTransformin the code architecture.PowerScale: --> Do we have to redefine this inhirited method ?set_default_locators_and_formatters(self, axis)yacth commentedon Jun 25, 2021
If I add this line :
just before the
PowerNorm()class in thecolors.py, it means I should access the kwargs for thePowerScale()in thescale.pyfile, am I right ?Because I am trying to use them but in visual studio it says for example for
vminthat"vmin" is not defined.Adding PowerScale for PowerNorm matplotlib#20355
SHRISHTISHUKLA-0 commentedon Jan 30, 2025
hello
does this issue is still open to contribute??
nixkitax commentedon Aug 26, 2025
Hello, since some time has passed, I'll try to contribute to this issue!
Impaler343 commentedon Aug 27, 2025
In the current implementation of
make_norm_from_scalethe value, vmin, and vmax are normalized after transformation as:f(value) - f(v_min) / (f(v_max) - f(v_min)).However in case of
PowerNorm, the expected behavior is normalizing before transformation as:f((value - vmin) / (vmax - vmin)).One possible solution, is to add an optional boolean argument to
make_norm_from_scalethat changes the order in which transformation and normalization is applied (for example,norm_before_trf).The new signature would look like:
In the
ScaleNormclass:Which path should we follow? @jklymak
jklymak commentedon Aug 27, 2025
Why is PowerNorm different? Sorry, I've not kept up with power norm and have never personally used it.
Impaler343 commentedon Aug 27, 2025
Quoting the first half of this comment
It seems that, doing normalization before transformation:
((a - vmin) / (vmax - vmin))**gammais how PowerNorm is defined / expected to function.If normalization is done after transformation (like other norms), the formula changes to
(a**gamma - vmin**gamma)/(vmax**gamma - vmin**gamma).rxchitrx commentedon Aug 28, 2025
Hi! I'm interested in working on this issue. I'm new to open source contributions but have been learning Python and would like to add the
scaleparameter to PowerNorm to make it consistent with other normalizers.Based on the discussion, it looks like I need to:
scaleparameter to PowerNorm's init methodIs anyone else currently working on this? If not, I'd like to give it a try!
Impaler343 commentedon Aug 29, 2025
@rxchitrx Im working on this and will open a PR soon
rxchitrx commentedon Sep 10, 2025
I've opened a PR to address this issue: #[30542]
The implementation adds a
scaleparameter to PowerNorm that allows pre-scaling of input data before normalization. It maintains full backward compatibility (scale defaults to 1.0) and includes comprehensive tests.Feel free to review and provide feedback!
rxchitrx commentedon Sep 10, 2025
I see the mypy-stubtest is failing because the type stub file needs to be updated to include the new
scaleparameter. Should I updatelib/matplotlib/colors.pyito add thescaleparameter to the PowerNorm__init__signature, or would you prefer to handle this differently?Happy to make any changes you'd recommend!