Fix 1d plots y-axis limits when toggling log-scale with buttons and fix 2d plot colorbar when Inf values #2426
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
Note that the issue only appeared when using the toolbar button. Doing
sc.plot(..., norm='log')
found the correct limits.Before:
After:
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)Before:
After: