-
Notifications
You must be signed in to change notification settings - Fork 390
MNT: update contour for mpl v3.8 #2213
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -45,7 +45,8 @@ | |||||||||||||||||||||
| from cartopy.mpl.slippy_image_artist import SlippyImageArtist | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| assert packaging.version.parse(mpl.__version__).release[:2] >= (3, 4), \ | ||||||||||||||||||||||
| _MPL_VERSION = packaging.version.parse(mpl.__version__) | ||||||||||||||||||||||
| assert _MPL_VERSION.release >= (3, 4), \ | ||||||||||||||||||||||
| 'Cartopy is only supported with Matplotlib 3.4 or greater.' | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # A nested mapping from path, source CRS, and target projection to the | ||||||||||||||||||||||
|
|
@@ -1602,12 +1603,15 @@ def contour(self, *args, **kwargs): | |||||||||||||||||||||
| result = super().contour(*args, **kwargs) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # We need to compute the dataLim correctly for contours. | ||||||||||||||||||||||
| bboxes = [col.get_datalim(self.transData) | ||||||||||||||||||||||
| for col in result.collections | ||||||||||||||||||||||
| if col.get_paths()] | ||||||||||||||||||||||
| if bboxes: | ||||||||||||||||||||||
| extent = mtransforms.Bbox.union(bboxes) | ||||||||||||||||||||||
| self.update_datalim(extent.get_points()) | ||||||||||||||||||||||
| if _MPL_VERSION.release[:2] < (3, 8): | ||||||||||||||||||||||
| bboxes = [col.get_datalim(self.transData) | ||||||||||||||||||||||
| for col in result.collections | ||||||||||||||||||||||
| if col.get_paths()] | ||||||||||||||||||||||
| if bboxes: | ||||||||||||||||||||||
| extent = mtransforms.Bbox.union(bboxes) | ||||||||||||||||||||||
| self.update_datalim(extent.get_points()) | ||||||||||||||||||||||
| else: | ||||||||||||||||||||||
| self.update_datalim(result.get_datalim(self.transData)) | ||||||||||||||||||||||
|
Contributor
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. Do we need to update the datalim here or is that already taken care of because it is a full collection that is added to the axes now? The other collection methods like scatter and pcolormesh don't update the datalims from their return objects. Maybe this has to do with the contour wrapping stuff and not getting the bounds until actually calling update_datalim()? This is mostly just my curiosity here.
Member
Author
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. I saw several test failures when I tried not having it. But now I look more closely I am questioning whether they matter. For example which comes from the second assertion here. So it fails because the non-transformed-first version is now the same as the transformed-first version. Without much context, more consistency seems like an improvement? cartopy/lib/cartopy/tests/mpl/test_contour.py Lines 137 to 146 in 41880a8
There are also some image test failures which, by eye, look like they might be because of a similar extent change to the above. We would need to add in something like
Contributor
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. Ahh, OK. I think we definitely need this then, thanks for checking. The two cases should definitely be different and that is preferable in these cases because their extents truly are different. The gallery kind of shows that if we force the extent to be global on the transformed-first one there is a gap and the extent is only -179/179 and doesn't touch the extreme edges. But, if we let the path logic do its magic it should be out to -180 and fill that gap. |
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| self.autoscale_view() | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -1650,12 +1654,15 @@ def contourf(self, *args, **kwargs): | |||||||||||||||||||||
| result = super().contourf(*args, **kwargs) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| # We need to compute the dataLim correctly for contours. | ||||||||||||||||||||||
| bboxes = [col.get_datalim(self.transData) | ||||||||||||||||||||||
| for col in result.collections | ||||||||||||||||||||||
| if col.get_paths()] | ||||||||||||||||||||||
| if bboxes: | ||||||||||||||||||||||
| extent = mtransforms.Bbox.union(bboxes) | ||||||||||||||||||||||
| self.update_datalim(extent.get_points()) | ||||||||||||||||||||||
| if _MPL_VERSION.release[:2] < (3, 8): | ||||||||||||||||||||||
| bboxes = [col.get_datalim(self.transData) | ||||||||||||||||||||||
| for col in result.collections | ||||||||||||||||||||||
| if col.get_paths()] | ||||||||||||||||||||||
| if bboxes: | ||||||||||||||||||||||
| extent = mtransforms.Bbox.union(bboxes) | ||||||||||||||||||||||
| self.update_datalim(extent.get_points()) | ||||||||||||||||||||||
| else: | ||||||||||||||||||||||
| self.update_datalim(result.get_datalim(self.transData)) | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| self.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.
set_pathsis not implemented for theContourSetalthough it is for other collections. I wonder if we should raise a feature request, although this use-case is pretty niche. I guess we would only have a problem ifget_pathsstarted returning a copy.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.
Yeah, I think this could make sense. It does seem a bit suspect to rely on changing the returned object here like this.
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.
Feature request now at matplotlib/matplotlib#26340.