-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
FIX: minor log ticks overwrite #13126
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
I think the change on
after which I don't know if the other changes (touching labelOnlyBase) are needed? |
Yeah that might be better. Not sure we should be implying that a locator is a minor locator. My preference would be that we just explicitly pass the major locator instance to anything we want to be a minor locator and then do a set diff between the two locators Or simply doing this in the axis code after the fact where we know about both locators. |
The log locator code already has "magic" to guess whether it's a minor or a major locator; given that it's already assuming that it works we may as well rely on it. |
I'd argue that the "magic" is probably a bad idea because it relies on the user knowing the magic when they specify the Locator, and as we have seen, even the developers don't get the "magic" right. I think there are two approaches - 1) tell the locator explicitly what ticks to avoid with an optional I guess I think 1) is the best because I can think of cases where the minorLocator might want to exclude a tick because it is close but not equal to a major tick. I don't see why we can't impliment this as a |
(BTW implimenting your change to squash the bug, the other discussion is more long-term) |
lib/matplotlib/ticker.py
Outdated
return AutoLocator().tick_values(vmin, vmax) | ||
ticklocs = AutoLocator().tick_values(vmin, vmax) | ||
# Don't overstrike the major labels. | ||
ticklocs = [t for t in ticklocs if |
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.
eh, that needs to use boolean indexing, no?
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.
Not sure what you mean? Your version didn't work because ticklocs is an array and is_close_to_int
only works on a single value. This seems to work...
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.
My patch also fixed is_close_to_int to be vectorized: it deleted the lines
- if not np.isfinite(x):
- return False
you may have missed that?
(if x
is not finite, the expression below will also be false).
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.
Ah, my fault.
I would name this |
6e15b71
to
5c9d3bd
Compare
lib/matplotlib/ticker.py
Outdated
# Don't overstrike the major labels. | ||
ticklocs = ticklocs[ | ||
~is_close_to_int(np.log(ticklocs) / np.log(b))] | ||
print('ticklocs', ticklocs) |
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.
remove this line
lib/matplotlib/ticker.py
Outdated
@@ -2250,13 +2248,19 @@ def tick_values(self, vmin, vmax): | |||
ticklocs = b ** decades | |||
|
|||
_log.debug('ticklocs %r', ticklocs) | |||
print('subs', subs, have_subs, ticklocs) |
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.
remove this line
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.
Oooops, sorry
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.
I guess that can count as Jody's approval of my patch :)
ticklocs = AutoLocator().tick_values(vmin, vmax) | ||
# Don't overstrike the major labels. | ||
ticklocs = ticklocs[ | ||
~is_close_to_int(np.log(ticklocs) / np.log(b))] |
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.
This looks like a hard-coded assumption on the position of the major ticks. Will this fail if I’ve set non-default values no the major locator?
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.
Absolutely. See discussion above for fixing that. But that assumption is already in the code, this just makes that assumption work properly under all conditions. The next step is to get rid of the assumption, but thats a bigger project.
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.
Ok, that's reasonable for now. However, it would be good to explicitly document this in the code with a comment (unless you're immediately following up with the full fix).
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.
Sure thing
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.
Anybody can merge after CI pass.
Owee, I'm MrMeeseeks, Look at me. There seem to be a conflict, please backport manually. Here are approximate instructions:
And apply the correct labels and milestones. Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon! If these instruction are inaccurate, feel free to suggest an improvement. |
Automatic backport fails due to #12865 not being backported. We should either backport both or none. |
Moved both to 3.1. The logic around the log ticks is subtle and probably better to keep changes to it for minor release (not patch releases). |
PR Summary
attempting to fix log overprint issue (closes #13112)
Before:
After
PR Checklist