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

Ignore masked values for determining canvas and colorbar ranges #292

Merged
merged 22 commits into from
Jan 12, 2024

Conversation

nvaytet
Copy link
Member

@nvaytet nvaytet commented Jan 10, 2024

Fixes #266

As always, it turned out more complicated than expected. I needed to handle a bunch of different cases with coordinates that contain strings or datetimes.

For the latter, logscale on a datetime axis currently does not crash but no padding is applied.
It is an edge case anyway, and renders funny in matplotlib. I don't think it is very useful as a plot.
At least it doesn't crash so users can anyway set their own limits.

@jokasimr
Copy link
Contributor

Yeah this looks like a better solution. The autoscaling logic doesn't leak into the Line class and we don't get the problem that the limits aren't updated when the scale is changed.

@jokasimr
Copy link
Contributor

About the padding breaking the tests, perhaps we should make the padding width a global config and then import it both in limits.py and in the tests.
This would also let the user tweak it if they want to.

@nvaytet nvaytet marked this pull request as ready for review January 11, 2024 12:10
@nvaytet
Copy link
Member Author

nvaytet commented Jan 11, 2024

About the padding breaking the tests, perhaps we should make the padding width a global config and then import it both in limits.py and in the tests.
This would also let the user tweak it if they want to.

We used to have a global configuration file which was mostly used for the plotting.

I thought it would be useful for users to be able to set their prefered colormap, or their line-style. But it led to some annoyances in the code. When we migrated to Plopp, we left the config file out. No one has really complained that it was removed/missing.

I agree that users may not want to set the padding or the line color as a kwarg every time they make a plot, which is why I thought of having such a config file initially. However, it seems that most people are just happy with the default Plopp/Matplotlib gives you, and that if they really need to control every aspect of the figure (for a paper for example), then they typically just set parameters for that one figure. It's not so bothersome.

So I would say, for now, we don't do the config file. But if people start asking for it, we will re-instate it.

Copy link
Contributor

@jokasimr jokasimr left a comment

Choose a reason for hiding this comment

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

Looks good to me! Just have some minor comments.

Return the union of this bounding box with another one.
"""
return BoundingBox(
xmin=min(self.xmin or np.inf, other.xmin or np.inf),
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't this break if self.xmin == 0? I think we need to explicitly check for None here even if it is more verbose. Or perhaps we can set the defaults already in the constructor?

self._xmax = np.NINF
self._ymin = np.inf
self._ymax = np.NINF
self._bbox = BoundingBox()
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it be possible to have this only be a local variable in the autoscale() method? I saw that it is used in logy but I didn't really understand why.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's also used in autoscale itself. It's used as a global memory of the range. It is needed when you are in a mode where you allow the plot limits to grow but not shrink.
The default is that the range follow the data, but you can also set a mode where limits grow, maybe giving a better feel for the relative differences in the data.

See the autoscale parameter in https://scipp.github.io/plopp/reference/generated/plopp.plot.html#plopp.plot

@nvaytet
Copy link
Member Author

nvaytet commented Jan 11, 2024

I now realise I also need to apply this to the plotly backend.

@nvaytet nvaytet requested a review from jokasimr January 11, 2024 16:00
"""
Find sensible limits, depending on linear or log scale.
If there are no finite values in the array, raise an error.
If there are no positive values in the array, and the scale is log, fall back to
some sensible default values.
"""
if scale is None:
Copy link
Contributor

@jokasimr jokasimr Jan 12, 2024

Choose a reason for hiding this comment

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

Minor: Since we are not doing anything special with the scale=None case it seems to me that it would be nicer to leave scale as linear/log here and let the caller worry about the None case.

from scipp import Variable, scalar
import scipp as sc

from .utils import merge_masks


def find_limits(
Copy link
Contributor

Choose a reason for hiding this comment

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

Is find_limits called anywhere with a Variable valued argument for x?

Copy link
Member Author

Choose a reason for hiding this comment

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

It shouldn't be the case anymore, because we are querying the .masks property of x.

@nvaytet nvaytet merged commit 829986d into main Jan 12, 2024
3 checks passed
@nvaytet nvaytet deleted the masked-limits-test branch January 12, 2024 13:57
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.

Allow other ways of handling masks?
2 participants