Skip to content

Validate steps input to MaxNLocator #7578

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

Closed
4 of 5 tasks
QuLogic opened this issue Dec 7, 2016 · 8 comments
Closed
4 of 5 tasks

Validate steps input to MaxNLocator #7578

QuLogic opened this issue Dec 7, 2016 · 8 comments
Milestone

Comments

@QuLogic
Copy link
Member

QuLogic commented Dec 7, 2016

NOTE The following was actually incorrect as the steps input was invalid; thus this ticket has been modified slightly to note the fact that steps should be validated in some manner.

Differences in MaxNLocator between 2.0.0 and 1.5.3 may be minimized by ensuring steps is between 1 and 10 and the classic style is used.


I ran the Cartopy test suite against v2.0.0rc1 and there appear to be some changes in the result from MaxNLocator. The default style change page only references changes to AutoLocator and the API changes page mentions LinearScaleLocator. I don't see any obvious changes in the tests for MaxNLocator, so I guess this is a bug, or needs to be better documented.

Here is the result on 1.5.3:

python
>>> import matplotlib
>>> matplotlib.__version__
'1.5.3'
>>> from matplotlib.ticker import MaxNLocator
>>> degree_locator = MaxNLocator(nbins=9, steps=[1, 2, 3, 6, 15, 18])
>>> degree_locator.tick_values(-180, 180)
array([-180., -120.,  -60.,    0.,   60.,  120.,  180.])
>>> degree_locator.tick_values(-50000000.0, 50000000.0)
array([-60000000., -40000000., -20000000.,         0.,  20000000.,
        40000000.,  60000000.])
>>> degree_locator.tick_values(-61.2479231, 68.41835367)
array([-80., -60., -40., -20.,   0.,  20.,  40.,  60.,  80.])

and here is the result with v2.0.0rc1

python
>>> import matplotlib
>>> matplotlib.__version__
'2.0.0rc1'
>>> from matplotlib.ticker import MaxNLocator
>>> degree_locator = MaxNLocator(nbins=9, steps=[1, 2, 3, 6, 15, 18])
>>> degree_locator.tick_values(-180, 180)
array([-180., -120.,  -60.,    0.,   60.,  120.,  180.])
>>> degree_locator.tick_values(-50000000.0, 50000000.0)
array([-60000000., -45000000., -30000000., -15000000.,         0.,
        15000000.,  30000000.,  45000000.,  60000000.])
>>> degree_locator.tick_values(-61.2479231, 68.41835367)
array([-75., -60., -45., -30., -15.,   0.,  15.,  30.,  45.,  60.,  75.])
  • Matplotlib version, Python version and Platform (Windows, OSX, Linux ...): 2.0.0rc1, conda's 3.5.2, Linux
  • How did you install Matplotlib and Python (pip, anaconda, from source ...): from source
  • If possible please supply a Short, Self Contained, Correct, Example
    that demonstrates the issue i.e a small piece of code which reproduces the issue
    and can be run with out any other (or as few as possible) external dependencies.
  • If this is an image generation bug attach a screenshot demonstrating the issue.
  • If this is a regression (Used to work in an earlier version of Matplotlib), please
    note where it used to work.
@QuLogic QuLogic added this to the 2.0 (style change major release) milestone Dec 7, 2016
@QuLogic
Copy link
Member Author

QuLogic commented Dec 7, 2016

Bisect points to

9982e400c7b21afdebe364d8eb1a8565c5383242 is the first bad commit
commit 9982e400c7b21afdebe364d8eb1a8565c5383242
Author: Thomas A Caswell <tcaswell@gmail.com>
Date:   Mon Aug 22 15:57:53 2016 -0400

    Merge pull request #6919 from efiring/integer_locator
    
    ENH: Rework MaxNLocator, eliminating infinite loop; closes #6849

:040000 040000 95c51fc30de8968e26068ffb49d5e7323a2ca0a6 2782be8d70b37e6658f1e896ccbd217e142be26b M	lib

the backport of #6919. cc @efiring.

@efiring
Copy link
Member

efiring commented Dec 7, 2016

First, evidently cartopy was using a steps kwarg that was inconsistent with the API; the fact that it worked was accidental. To be consistent with the API, the equivalent steps array would be steps=[1, 1.5, 1.8, 2, 3, 6, 10]. As the docstring says, it must start with 1 and end with 10. If you had used that steps array, you would have gotten yet another result with v1.5:

In [4]: degree_locator = MaxNLocator(nbins=9, steps=[1, 1.5, 1.8, 2, 3, 6, 10])

In [5]: degree_locator.tick_values(-61.2479231, 68.41835367)
array([-72., -54., -36., -18.,   0.,  18.,  36.,  54.,  72.])

Second, I think the difference in behavior is an improvement, in that it does a better job of getting close to the target (maximum) number of bins (tick intervals within the limits), given the available steps.

I will add a note to the documentation, but I don't consider the new behavior to be a bug and I will not try to restore the old behavior. This will be one of the relatively few areas where behavior in 2.0, even with classic settings, is not exactly the same as in 1.5.x.

Evidently I also need to add validation of the steps kwarg.

@NelleV
Copy link
Member

NelleV commented Dec 7, 2016

I'm moving this to milestone 2.1

@NelleV NelleV modified the milestones: 2.1 (next point release), 2.0 (style change major release) Dec 7, 2016
@QuLogic
Copy link
Member Author

QuLogic commented Dec 7, 2016

Maybe the validation part, but this issue is a missing documentation problem of a change in 2.0; it should go in 2.0, or at most 2.0.1.

@NelleV
Copy link
Member

NelleV commented Dec 7, 2016

I am fine with the documentation being into 2.0, but we need to be extremely careful about not tagging too much issue into 2.0, else we will never release 2.0. There are way too many issues and PR being tagged 2.0.1.
IMO, now that we have a release candidate, the smallest amount possible of commits should go in the 2.0. Nothing prevents us from releasing 2.1 soon after.

@QuLogic QuLogic modified the milestones: 2.0 (style change major release), 2.1 (next point release) Dec 7, 2016
@QuLogic
Copy link
Member Author

QuLogic commented Dec 7, 2016

The 2.0.1 milestone is irrelevant for the purposes of releasing 2.0; it's a nice-to-have list, but not that important.

For 2.0, I bumped everything that's not documentation or imminent (I assume @tacaswell wants those last two features in) or a regression.

@QuLogic
Copy link
Member Author

QuLogic commented Dec 7, 2016

Wait wait, I forgot one very important thing; tests were run in classic style to minimize differences with older releases. If I compare classic mode with 1.5.3, then using the valid steps values, I can get a consistent result, and that's really all I was hoping for because otherwise we need either a bunch of test images or a really high test tolerance.

So I must apologize for all the milestone flipping, but since this is only a problem when given invalid input, I guess it's not that important to document in 2.0 specifically. We only really need the validation part, which can go into 2.1.

@QuLogic QuLogic modified the milestones: 2.1 (next point release), 2.0 (style change major release) Dec 7, 2016
@QuLogic QuLogic changed the title Changes in MaxNLocator in v2.0.0rc1 Validate steps input to MaxNLocator Dec 7, 2016
@efiring
Copy link
Member

efiring commented Dec 7, 2016

I have the validation plus a bugfix (an inconsistency with "integer=True") ready to go, and I will add a doc note soon and then make a PR. With the reimplementation of the inner algorithm in MaxNLocator I think there will be cases where the result differs, so it would be good to mention this. I don't see any problem with including it in 2.0. With luck I will have the PR ready tonight.

@QuLogic QuLogic closed this as completed in fe721a6 Dec 9, 2016
@QuLogic QuLogic modified the milestones: 2.0 (style change major release), 2.1 (next point release) Dec 9, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants