You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should points with a single infinite coordinate be masked or clipped? #10452
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.
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.
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?
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.
Most arguments have already been made in the linked issue, so I'm just giving the short version here.
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.
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.
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.
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!
Activity
efiring commentedon 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
infadds considerable complexity for very little gain.ImportanceOfBeingErnest commentedon Feb 14, 2018
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
the result would be the following?
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 commentedon Feb 14, 2018
Most arguments have already been made in the linked issue, so I'm just giving the short version here.
The suggested behavior is not particularly complex to support, because we already need to clip values larger than
2**24because 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.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 commentedon Feb 15, 2018
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.
github-actions commentedon Mar 18, 2024
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!
anntzer commentedon Mar 18, 2024
Let's close this as "unlikely to ever happen".