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

Fix 1d plots y-axis limits when toggling log-scale with buttons and fix 2d plot colorbar when Inf values #2426

Merged
merged 3 commits into from Feb 8, 2022

Conversation

nvaytet
Copy link
Member

@nvaytet nvaytet commented Feb 8, 2022

1d plots:

Toggling to log scale using the toolbar button when the current axis limit goes below 0 (which is quite common because we add a little padding around the range of values) would cause the axis to completely mess up.
This is due to a behaviour in matplotlib that when axis limits are not explicitly set, the change to log scale correctly figrues out the limits, but when the limits are set (and we always set the limits), then it tries to use the number that were set and it gets a negative number as the starting point for the log scale.

We now use rescale_to_data to set the limits on the axis before changing the axis scaling to log.

Example:

import scipp as sc
sc.plot(sc.arange('x', 100.))

Note that the issue only appeared when using the toolbar button. Doing sc.plot(..., norm='log') found the correct limits.

Before:
Screenshot at 2022-02-08 14-30-53

After:
Screenshot at 2022-02-08 14-37-39

2d plots:

Issue when trying to find colorbar limits when Inf values present (which happens often when you are normalizing and you divide by 0)

import numpy as np
import scipp as sc

a = np.arange(100.0)
a[0] = np.nan
a[-1] = np.inf
b = sc.array(dims=['x'], values=a, unit='K').fold('x', sizes={'x': 10, 'y': -1})
sc.plot(b)

Before:
Screenshot at 2022-02-08 14-28-47

After:
Screenshot at 2022-02-08 14-42-36

"""
v = values(x).values
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this just x.values?

@SimonHeybrock SimonHeybrock merged commit 4013fd6 into main Feb 8, 2022
@SimonHeybrock SimonHeybrock deleted the fix_norm_limits branch February 8, 2022 14:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants