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
matplotlib.ticker.LinearLocator view_limits algorithm improvement? #6142
Milestone
Comments
A pull request would help to clairify (and will allow the tests to run). |
provisionally tagging an 2.0 in case we like this change and it breaks tests, can be pushed out if needed. |
maqifrnswa
added a commit
to maqifrnswa/matplotlib
that referenced
this issue
Mar 11, 2016
No problem, here's a pull request: |
tacaswell
modified the milestones:
2.1 (next point release),
2.0 (style change major release)
Mar 14, 2016
maqifrnswa
added a commit
to maqifrnswa/matplotlib
that referenced
this issue
Mar 29, 2016
tacaswell
added a commit
that referenced
this issue
May 4, 2016
API: ticker.LinearLocator view_limits algorithm changes closes #6142
QuLogic
modified the milestones:
2.0 (style change major release),
2.1 (next point release)
May 12, 2016
tacaswell
added a commit
that referenced
this issue
May 13, 2016
API: ticker.LinearLocator view_limits algorithm changes closes #6142
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspecting the code of matplotlib.ticker.LinearLocator
matplotlib/lib/matplotlib/ticker.py
Line 1161 in 7d1a7c2
you can see that the view limits are chosen such that the difference between vmin and vmax is an interger multiple of scale, which is itself a power of 10. Therefore, the range will be nicely divisible when divided by 10 (11 tickmarks).
matplotlib/lib/matplotlib/ticker.py
Line 1213 in 7d1a7c2
Therefore, the view_limits function determines the limits assuming there are 11 ticks. This assumption is implicit in two lines:
matplotlib/lib/matplotlib/ticker.py
Line 1224 in 7d1a7c2
matplotlib/lib/matplotlib/ticker.py
Line 1227 in 7d1a7c2
Code is repeated here:
Since we know the number of ticks, from
self.num_ticks
, we can generalize the current algorithm to be better suited for any number of ticks. Suggested generalized algorithm:This generalized expression reduces to the current form when
self.num_ticks==11
(which is the current default). For other cases, here is an example:when num_ticks = 10, vmin = 20, vmax=90
Current algorithm returns vmin = 20, vmax=90, corresponding to ticks spaced by 7.77778.
The proposed algorithm returns vmin = 18, vmax = 90, corresponding to ticks spaced by 8.
Is this something worth doing? The patch is trivial -- just changing two lines of code. I can turn this in to a pull request to illustrate if it is helpful.
The text was updated successfully, but these errors were encountered: