Skip to content

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

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
anntzer opened this issue Feb 14, 2018 · 6 comments
Closed

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

anntzer opened this issue Feb 14, 2018 · 6 comments

Comments

@anntzer
Copy link
Contributor

anntzer commented Feb 14, 2018

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.

@anntzer anntzer added this to the v3.0 milestone Feb 14, 2018
@efiring
Copy link
Member

efiring commented Feb 14, 2018

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.

@ImportanceOfBeingErnest
Copy link
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.

@anntzer
Copy link
Contributor Author

anntzer commented Feb 14, 2018

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.

@ImportanceOfBeingErnest
Copy link
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.

@tacaswell tacaswell modified the milestones: v3.0, v3.1 Aug 11, 2018
@tacaswell tacaswell modified the milestones: v3.1.0, v3.2.0 Mar 18, 2019
@anntzer anntzer modified the milestones: v3.2.0, v3.3.0 Aug 7, 2019
@QuLogic QuLogic modified the milestones: v3.3.0, v3.4.0 May 7, 2020
@QuLogic QuLogic modified the milestones: v3.4.0, v3.5.0 Jan 27, 2021
@QuLogic QuLogic modified the milestones: v3.5.0, v3.6.0 Sep 25, 2021
@QuLogic QuLogic modified the milestones: v3.6.0, v3.7.0 Jul 8, 2022
@QuLogic QuLogic modified the milestones: v3.7.0, future releases Jan 26, 2023
Copy link

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Mar 18, 2024
@anntzer
Copy link
Contributor Author

anntzer commented Mar 18, 2024

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

@anntzer anntzer closed this as completed Mar 18, 2024
@tacaswell tacaswell closed this as not planned Won't fix, can't repro, duplicate, stale Mar 18, 2024
@QuLogic QuLogic removed the status: inactive Marked by the “Stale” Github Action label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants