Currently, Rectangles with zero-width and zero-height are ignored for autoscaling purposes, but not other zero-sized patches:
frommatplotlibimportpatches, pyplotaspltax=plt.figure().add_subplot()
ax.add_patch(patches.Rectangle((-5, -5), 0, 0)) # zero-sized at (-5, -5)ax.add_patch(patches.Circle((5, 5), 0)) # zero-radius at (5, 5)ax.relim()
ax.autoscale_view()
plt.show()
results in axes autoscaled around (5, 5) (so they include the circle, but not the rectangle). I would argue that Rectangles should never be ignored, even if they have zero-width and zero-height, both for consistency with other patches, and because such Rectangles are likely not drawn with no reason.
This behavior (implemented in Axes._update_patch_limits) was introduced in f24d06c to support log-scaled histograms with empty bins, but is not necessary anymore as hist autoscaling was fully reworked in #14581, making this behavior unnecessary (the check in _update_patch_limits can be deleted with no bad effects); perhaps it was even already unnecessary before though.
Also, note that #2942 already weakened the original patch by going from ignoring Rectangles with zero width OR height to only ignoring Rectangles with zero width and height.
Wasn't there something a long while back for including this for regular
(not log-based) hist/bar graphs that had an empty bar on the edges that was
getting clipped out by auto-limits? Or is that handled separately?
On Mon, Dec 7, 2020 at 5:50 PM Antony Lee ***@***.***> wrote:
Currently, Rectangles with zero-width and zero-height are ignored for
autoscaling purposes, but not other zero-sized patches:
from matplotlib import patches, pyplot as plt
ax = plt.figure().add_subplot()ax.add_patch(patches.Rectangle((-5, -5), 0, 0)) # zero-sized at (-5, -5)ax.add_patch(patches.Circle((5, 5), 0)) # zero-radius at (5, 5)ax.relim()ax.autoscale_view()plt.show()
results in axes autoscaled around (5, 5) (so they include the circle, but
not the rectangle). I would argue that Rectangles should never be ignored,
even if they have zero-width and zero-height, both for consistency with
other patches, and because such Rectangles are likely not drawn with no
reason.
This behavior (implemented in Axes._update_patch_limits) was introduced
in f24d06c
<f24d06c>
to support log-scaled histograms with empty bins, but is not necessary
anymore as hist autoscaling was fully reworked in #14581
<#14581>, making this
behavior unnecessary (the check in _update_patch_limits can be deleted
with no bad effects); perhaps it was even already unnecessary before though.
Also, note that #2942 <#2942>
already weakened the original patch by going from ignoring Rectangles with
zero width OR height to only ignoring Rectangles with zero width and height.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#19081>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHF6HSSN7LBWFQJXEJA3DSTVLZVANCNFSM4UREBBGQ>
.
I'm not sure what you are referring to, but in any case hist([4, 5, 6], range(10)) (for example, which does have empty bins on the sides) is not affected by the suggested removal (the empty bins are clearly included for autoscaling, with or without the snippet).
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
WeatherGod commented on Dec 7, 2020
anntzer commented on Dec 8, 2020
I'm not sure what you are referring to, but in any case hist([4, 5, 6], range(10)) (for example, which does have empty bins on the sides) is not affected by the suggested removal (the empty bins are clearly included for autoscaling, with or without the snippet).
timhoffm commented on Dec 28, 2020
IMHO zero-sized Rectangles should be taken into account.
If users don't want them, they will be able to exclude them via #15595 (once that is in). But excluding should be explicit.
github-actions commented on Sep 18, 2023
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!