Skip to content

Should points with a single infinite coordinate be masked or clipped? #10452

Closed as not planned

Description

@anntzer

Initially raised in #9305 (comment) (and following comment).

We realized in 2.1 that there is a reasonable argument for plt.plot([1, 1], [1, np.inf]) to draw a semi-infinite vertical line and plt.plot([1, 1], [-np.inf, np.inf]) to draw an infinite vertical line by default (by having the renderer clip infinities instead of masking them). Right now log scale allows both clipping and masking behavior, but linear scale always masks.

Of course this is a breaking change, so I'm just opening this for discussion.

Activity

  1. added
    API: changesChanges to the public API, typically requiring deprecation.
    on Feb 14, 2018
  2. added this to the milestone on Feb 14, 2018
  3. efiring commented on Feb 14, 2018

    @efiring
    Member

    I think that infinities should be treated as invalid for plotting purposes, and therefore they should be masked. Building in special treatment for inf adds considerable complexity for very little gain.

  4. ImportanceOfBeingErnest commented on Feb 14, 2018

    @ImportanceOfBeingErnest
    Member

    If I understand this proposal correctly you would want to add some vertical line from the last valid point towards infinity. So with this code

    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.linspace(-3,3,13)
    
    plt.plot(x, x/(x-1), marker="o")
    plt.margins(y=0.3)
    plt.show()
    

    the result would be the following?

    image

    That is hardly understandable. And you have no chance of knowing the user wanted to plot x/(x-1) in order to produce the first line correctly pointing towards -inf.

    Next how about the margins? If the lines are clipped at the axes boundary, this effectively ignores the margin set. However, a margin is usually set precisely not to have the plot be tight to the boundaries.

  5. anntzer commented on Feb 14, 2018

    @anntzer
    ContributorAuthor

    Most arguments have already been made in the linked issue, so I'm just giving the short version here.

    1. The suggested behavior is not particularly complex to support, because we already need to clip values larger than 2**24 because they would overflow the fixed point representation internally used by agg (and cairo, and ghostscript (which has an even lower limit), etc.). We even have a test for that (test_simplification::test_clipping). So it would just be a matter of only masking out nans instead of masking out both nans and infs, and then let the infs be clipped by the already existing codepath.

    2. When using log-scale, there are many cases where the expected behavior is to clip and not to mask (see Force clipped-log when drawing log-histograms. #9305 and linked issues, we noticed this shortly after 2.1.0 was released with a change in behavior towards masking, and reverted to (modified) clipping in 2.1.1). Now it is true that clipping can also give confusing results (as mentioned by @ImportanceOfBeingErnest) so it's a tradeoff as always. @tacaswell did mention support for the suggestion, so I was just opening this for discussion.

    I don't see how the margins are a problem, they would as always be computed ignoring the infinite points.

  6. ImportanceOfBeingErnest commented on Feb 15, 2018

    @ImportanceOfBeingErnest
    Member

    The point about margins is not how they are calculated, but about the expected visual appearance. If I set some margin around the plot I would expect there to be no lines within this margin. The proposed change would counteract this expectation, because those infinity-line would appear in the plot in the region where I don't want to have any lines due to my setting of margins.

    In that sense, whatever you do, just make sure to include the option to turn those infinity-lines off in the rcParams.

  7. modified the milestones: v3.0, v3.1 on Aug 11, 2018
  8. modified the milestones: v3.1.0, v3.2.0 on Mar 18, 2019
  9. modified the milestones: v3.2.0, v3.3.0 on Aug 7, 2019
  10. modified the milestones: v3.3.0, v3.4.0 on May 7, 2020
  11. modified the milestones: v3.4.0, v3.5.0 on Jan 27, 2021
  12. modified the milestones: v3.5.0, v3.6.0 on Sep 25, 2021
  13. modified the milestones: v3.6.0, v3.7.0 on Jul 8, 2022
  14. github-actions commented on Mar 18, 2024

    @github-actions

    This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

  15. anntzer commented on Mar 18, 2024

    @anntzer
    ContributorAuthor

    Let's close this as "unlikely to ever happen".

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

    API: changesChanges to the public API, typically requiring deprecation.

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions