Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork7.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 ourterms of service andprivacy 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?
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
``Axes.add_collection(..., autolim=True)`` updates view limits | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
``Axes.add_collection(..., autolim=True)`` has so far only updated the data limits. | ||
Users needed to additionally call `.Axes.autoscale_view` to update the view limits. | ||
View limits are now updated as well if ``autolim=True``, using a lazy internal | ||
update mechanism, so that the costs only apply once also if you add multiple | ||
collections. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -177,4 +177,3 @@ | ||
offset_transform=ax.transData, # Propagate transformations of the Axes | ||
) | ||
ax.add_collection(collection) | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -2331,6 +2331,23 @@ def add_child_axes(self, ax): | ||
def add_collection(self, collection, autolim=True): | ||
""" | ||
Add a `.Collection` to the Axes; return the collection. | ||
Parameters | ||
---------- | ||
collection : `.Collection` | ||
The collection to add. | ||
autolim : bool | ||
Whether to update data and view limits. | ||
.. versionchanged:: 3.11 | ||
This now also updates the view limits, making explicit | ||
calls to `~.Axes.autoscale_view` unnecessary. | ||
As an implementation detail, the value "_datalim_only" is | ||
scottshambaugh marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page.
dstansby marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
supported to smooth the internal transition from pre-3.11 | ||
behavior. This is not a public interface and will be removed | ||
again in the future. | ||
""" | ||
_api.check_isinstance(mcoll.Collection, collection=collection) | ||
if not collection.get_label(): | ||
@@ -2356,6 +2373,8 @@ def add_collection(self, collection, autolim=True): | ||
# This ensures that log scales see the correct minimum. | ||
points = np.concatenate([points, [datalim.minpos]]) | ||
self.update_datalim(points) | ||
if autolim != "_datalim_only": | ||
self._request_autoscale_view() | ||
self.stale = True | ||
return collection | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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,autolim=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. These are decorations on the colorbar and should not influence its limits. | ||
self._locator=None | ||
self._minorlocator=None | ||
@@ -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,autolim=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
self.stale=True | ||
defupdate_ticks(self): | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -163,5 +163,7 @@ def tripcolor(ax, *args, alpha=1.0, norm=None, cmap=None, vmin=None, | ||
corners = (minx, miny), (maxx, maxy) | ||
ax.update_datalim(corners) | ||
ax.autoscale_view() | ||
# TODO: check whether the above explicit limit handling can be | ||
# replaced by autolim=True | ||
ax.add_collection(collection, autolim=False) | ||
Comment on lines +166 to +168 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. Since there is an explicit | ||
return collection |
Uh oh!
There was an error while loading.Please reload this page.