-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
fix minor grid overlapping #11762
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 minor grid overlapping #11762
Conversation
|
lib/matplotlib/ticker.py
Outdated
locs = locs.compress(cond) | ||
mod = np.abs((locs - t0) % majorstep) | ||
cond1 = mod > minorstep / 10.0 | ||
cond2 = ~np.isclose(mod, np.ones_like(mod)*majorstep) |
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.
cond2 = ~np.isclose(mod, majorstep)
does not 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.
You prob need to set atol=0
and just use rtol
(maybe with a larger value than default).
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.
👍 Yep, atol=0
did it.
879785b
to
818c973
Compare
There is some problem with testing this. The currently failing test only fails for the py3.5 environment with pinned environment, not the others. So it seems the Locator gives different output depending on some dependency. What's more strange is that I initially would have liked to include
for testing as well, but that failed locally when testing through py.test
but it passes when being run outside the testing suite,
So apparently the figures created within the test suite differ from the ones created through normal python? |
For sure the test images can be different because it uses its own styles. Its strange that you are getting a failure just on 3.5. How different are the minor ticks? |
818c973
to
483b78f
Compare
483b78f
to
07f5682
Compare
I did not find the reason why the 3.5 environment behaves differently. The issue is that creating minor ticks in the range (0, 0.11e-12) produces a tick at the edge value In any case, I changed the limits for the test such that this problem is circumvented; because after all, we do not want to test the number of ticks with this, but rather whether minor tick positions overlap with major ones. This is what the test does now. |
tag - "sion" + "ew" |
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.
Sounds like a reasonable fix to the problem, based on the description of the issue under the hood and the new extensive test passing.
|
||
ax.minorticks_on() | ||
ax.grid(True, 'minor', 'y', linewidth=1) | ||
ax.grid(True, 'major', color='k', linewidth=1) |
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.
Wouldn't something like
ax.grid(which="both", axis="y") # or ax.grid(True, which="both", axis="y")
be enough to replace the 2 calls to `ax.grid`` (as one does not need the bare eye checking step here)? But even if that is the case, not really worth blocking the PR for so little IMHO...
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.
Well, I guess for the test itself we do not actually need any grid; this is more for the case that something goes wrong to easily see what it is. The point is, the previously present test should actually have made this issue apparent for anyone visualizing it with a grid - because it already had one number too much in it. So maybe keeping the grid in might help people looking at this in the future?
I am not 100 % comfortable with the side-issues reported by @ImportanceOfBeingErnest about the number of ticks, but I kind of agree that this seems to be outside of the current PR scope. |
I'll milestone for a backport as I dont' think there are any issues backporting this and it fixes a bug... |
…762-on-v2.2.x Backport PR #11762 on branch v2.2.x
PR Summary
Possible fix for #11758.
Here we run into the classic problem of
numerically. So in addition to the condition
a % b > something
we also can check ifa % b
is not actually close tob
itself (~np.isclose(a%b, b)
).Previously, the following code
would result in an overlapping grid line at y=0.06,
With this PR the output is as expected.
PR Checklist