-
Notifications
You must be signed in to change notification settings - Fork 1
Added PowerScale similar to LogScale as per 20355 #2
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
Conversation
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.
Thank you for opening your first PR into Matplotlib!
If you have not heard from us in a week or so, please leave a new comment below and that should bring it to our attention. Most of our reviewers are volunteers and sometimes things fall through the cracks.
You can also join us on gitter for real-time discussion.
For details on testing, writing docs, and our review process, please see the developer guide
We strive to be a welcoming and open project. Please follow our Code of Conduct.
r3kste
left a comment
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.
There are a few additional things we need to address before going forward. I have left some remarks.
In addition to this, you need to add 'power': PowerScale to the _scale_mapping dictionary in scale.py so that PowerScale is registered.
|
The below example code is giving an error after your recent commits. import matplotlib.pyplot as plt
import numpy as np
mosaic = [
["linear-log", "linear-power"],
["log-linear", "power-linear"],
]
fig, axs = plt.subplot_mosaic(mosaic, layout="constrained", figsize=(10, 6))
x = np.arange(0, 3 * np.pi, 0.1)
y = 2 * np.sin(x) + 3
for k, ax in axs.items():
x_scale, y_scale = k.split("-")
ax.set_xscale(x_scale)
ax.set_yscale(y_scale)
ax.set(xlabel=x_scale, ylabel=y_scale)
ax.plot(x, y)
plt.show()ErrorAttributeError: 'PowerScale' object has no attribute 'subs' |
|
In the current Because of this, it’s not possible to implement a there is no function f such that Given this, should we consider implementing a new version of |
|
In the current implementation of One possible solution, is to add an optional boolean argument to The new signature would look like: def make_norm_from_scale(scale_cls, base_norm_cls=None,*, init=None,
norm_before_trf=False):In the def __call__(self, value, clip=None):
...
if norm_before_trf:
t_value = value - self.vmin
t_value /= self.vmax - self.vmin
t_value = self._trf.transform(t_value).reshape(np.shape(t_value))
t_value = np.ma.masked_invalid(t_value, copy=False)
return t_value[0] if is_scalar else t_value
... |
|
Quoting the first half of this comment
It seems that, doing normalization before transformation: If normalization is done after transformation (like other norms), the formula changes to |
r3kste
left a comment
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.
There are some formatting issues which needs to be fixed.
r3kste
left a comment
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.
- Some stubs have to be updated in the corresponding
pyifiles - There are still some more formatting issues.
- There are disparities compared to other scales and transforms. Look into it more carefully.
import matplotlib.pyplot as plt
import numpy as np
import matplotlib.colors as colors
X, Y = np.mgrid[0:3:complex(0, 100), 0:2:complex(0, 100)]
Z = (1+np.sin(Y * 10)) * X**2
fig, ax = plt.subplots(2, 1)
pcm = ax[0].pcolormesh(X, Y, Z, cmap='PuBu_r', shading='nearest')
fig.colorbar(pcm, ax=ax[0], extend='max', label='linear scaling')
pcm = ax[1].pcolormesh(X, Y, Z, cmap='PuBu_r', shading='nearest',
norm=colors.PowerNorm(gamma=0.2, clip=True))
fig.colorbar(pcm, ax=ax[1], extend='max', label='PowerNorm')
plt.show()import matplotlib.pyplot as plt
import numpy as np
x = np.arange(400)
y = np.linspace(0.002, 1, 400)
fig, axs = plt.subplots(1, 1, figsize=(8, 8), layout='constrained')
axs.plot(x, y-y.mean())
axs.set_yscale('power', gamma=0.2,clip=True)
axs.set_title('power')
axs.grid(True)
plt.show()I used these two examples |
r3kste
left a comment
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.
@Sreekanth-M8 Apart from these review comments, there are also a couple more things left
- Add docstrings for the added/modified functions.
- The examples you provided in this comment are testing for
PowerNormandPowerScale. We also need a simple example forPowerTransformandInvertedPowerTransform.
import numpy as np
import matplotlib.pyplot as plt
from numpy.testing import assert_array_almost_equal
from matplotlib.scale import PowerTransform,InvertedPowerTransform
array = np.linspace(-0.5,1,200)
pt = PowerTransform(0.5)
ipt = InvertedPowerTransform(0.5)
transformed_array = pt.transform_non_affine(array)
new_array = ipt.transform_non_affine(transformed_array)
assert_array_almost_equal(array,new_array)
plt.plot(array,transformed_array)
plt.show() |
r3kste
left a comment
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.
704a213 to
8e1aec2
Compare
PR summary
closes 20355
Added
PowerTransformandPowerScale, to makePowerNormusing themake_norm_from_scaledecorator.In
PowerNormthe expected behavior is normalizing before transformation, unlike other scales which transform and then normalize. So I added a optional boolean argumentnorm_before_trftomake_norm_from_scalewhich controls whether normalization occurs before transformation or not.PR checklist