-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
ENH: ax.add_collection(..., autolim=True) updates view limits #29958
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
base: main
Are you sure you want to change the base?
Conversation
e5b0541
to
e7b2708
Compare
@@ -371,7 +371,7 @@ def __init__( | |||
colors=[mpl.rcParams['axes.edgecolor']], | |||
linewidths=[0.5 * mpl.rcParams['axes.linewidth']], | |||
clip_on=False) | |||
self.ax.add_collection(self.dividers) | |||
self.ax.add_collection(self.dividers, autolim=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are decorations on the colorbar and should not influence its limits.
@@ -805,7 +805,7 @@ def add_lines(self, *args, **kwargs): | |||
xy = self.ax.transAxes.inverted().transform(inches.transform(xy)) | |||
col.set_clip_path(mpath.Path(xy, closed=True), | |||
self.ax.transAxes) | |||
self.ax.add_collection(col) | |||
self.ax.add_collection(col, autolim=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here as well: These are decorations on the colorbar and should not influence its limits.
# TODO: check whether the above explicit limit handling can be | ||
# replaced by autolim=True | ||
ax.add_collection(collection, autolim=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since there is an explicit update_datalim(); autoscale_view()
above, autolim=True
has no effect. Setting autolim=False
for now to make that clear. We may whether the explicit handling can be removed in favor of autolim=True
, but I'll leave that for later.
e7b2708
to
a080a71
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's one more call in galleries/examples/lines_bars_and_markers/multicolored_line.py
that can probably be dropped?
@@ -177,4 +177,3 @@ | |||
offset_transform=ax.transData, # Propagate transformations of the Axes | |||
) | |||
ax.add_collection(collection) | |||
ax.autoscale_view() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The text above this still mentions autoscale_view
as required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed the whole section since Collections are no longer special in terms of autoscaling.
# Note: autolim=False is used to keep the view limits as is for now, | ||
# given the updated behavior of autolim=True to also update the view | ||
# limits. It may be reasonable to test the limits handling in the future | ||
# as well. This will require regenerating the reference image. | ||
ax.add_collection(pc, autolim=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this what the _datalim_only
option is for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both, False
and _datalim_only
do not update the view limits. The difference is that _datalim_only
updates the data limits. That difference is not relevant to the test, so both work.
However, _datalim_only
is only a temporary solution. Since it is not granted that we will update the test image for autolim=True
, we may have to switch to autolim=False
. Using it directly makes it thus simpler to remove _datalim_only
later.
This makes explicit calls to `autoscale_view()` or `_request_autoscale_view()` unnecessary. 3D Axes have a special `auto_scale_xyz()`, also there's a mixture of `add_collection()` and `add_collection3d()`. This needs separate sorting . I've added a private value `autolim="_datalim_only"` to keep the behavior for 3D Axes unchanged for now. That will be resolved by a follow-up PR. I believe it's getting too complicated if we fold this into the 2D change.
a080a71
to
5144212
Compare
This makes explicit calls to
autoscale_view()
or_request_autoscale_view()
unnecessary.3D Axes have a special
auto_scale_xyz()
, also there's a mixture ofadd_collection()
andadd_collection3d()
. This needs separate sorting . I've added a private valueautolim="_datalim_only"
to keep the behavior for 3D Axes unchanged for now. That will be resolved by a follow-up PR. I believe it's getting too complicated if we fold this into the 2D change.Also for follow-ups:
autoscale_view
it may be that we can now remove the explicit limits for some cases since the autoscaled view is good enough.autolim=True
, which is the default. We may remove these, but it seems they are sometimes used as explicit communication of intent. Also the comment inmatplotlib/galleries/examples/shapes_and_collections/collections.py
Line 62 in 492a478
autolim=False
may have been the default a long time ago. - This should be investigated (Edit: Indeed, the default was changed in 2007 by 0df13d7).Closes #29957.