Skip to content

Raise error if argument to xlim is invalid, e.g., nan #7460

Closed

Description

@anntzer

As of 2.0b4, passing nan as a limit to xlim seems to reset both limits to (-0.001, 0.001) (try e.g. with plt.plot([0, 1]); plt.xlim(right=np.nan)). I think this should either error, or, more usefully, be interpreted as None (i.e. leave that limit as is). (For extra points, we can also bikeshed what passing inf to xlim should mean.)

The main use case would be when the xlim is read from some float context (e.g. from an array) where you can easily store nan but not None.

Activity

  1. tacaswell commented on Nov 15, 2016

    @tacaswell
    Member

    Biased toward erroring, using np.nan as a stand in for None seems a bit too clever and surprising, but am open to be talked into it.

    From git-blame, I think that this behavior has been long standing (e356a15 in 2008 from @efiring )

  2. added this to the milestone on Nov 15, 2016
  3. NelleV commented on Nov 15, 2016

    @NelleV
    Member

    So your suggestion is to raise an error?

  4. NelleV commented on Nov 15, 2016

    @NelleV
    Member

    (I'd raise an error…)

  5. tacaswell commented on Nov 20, 2016

    @tacaswell
    Member

    That seems to be 1.5 votes to error.

  6. efiring commented on Nov 20, 2016

    @efiring
    Member

    Make that 2.5.

  7. anntzer commented on Nov 20, 2016

    @anntzer
    ContributorAuthor

    I'm fine with making it an error too. Same with inf?

  8. efiring commented on Nov 20, 2016

    @efiring
    Member

    Yes. Sounds like an np.isfinite check is in order.

  9. changed the title [-]let `xlim(left=np.nan, right=...)` be synonymous to `xlim(left=None, right=...)`[/-] [+]Raise error if argument to xlim is invalid, e.g., nan[/+] on Nov 27, 2016
  10. bcongdon commented on Jan 4, 2017

    @bcongdon
    Contributor

    Working on this now. It looks like np.isfinite raises an error if you pass it something non-numeric, like a date.

    Do we need the full np.isfinite check, or can we just reject np.nan and np.inf values?

  11. efiring commented on Jan 4, 2017

    @efiring
    Member

    I think you can handle that by putting the check after the calls to convert_xunits; I think that np.isfinite should be safe there.

  12. tacaswell commented on Mar 7, 2017

    @tacaswell
    Member

    We now have 3 PRs for this!

  13. added a commit that references this issue on Apr 13, 2017
  14. QuLogic commented on Apr 13, 2017

    @QuLogic
    Member

    Closed by #7744 and #8022.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Difficulty: Easyhttps://matplotlib.org/devdocs/devel/contribute.html#good-first-issues

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions