Fix base mesh plotting with cartopy 0.25 and matplotlib 3.11 - #972
Merged
Conversation
Creating gridline labels with draw_labels=True and then hiding some of
them (gl.top_labels = False, etc.) confuses cartopy's title placement.
GeoAxes._update_title_position() scans gl.top_label_artists whenever
gl.geo_labels is true (the default), so the hidden top labels are still
included. During a draw, their tight bounding boxes are infinite, so
the title ends up at y = inf and the axes tight bounding box becomes
non-finite.
The NaN then cascades: tight_layout() gives the axes a NaN position, the
"geo" spine path becomes all NaN, and cartopy's gridliner hands NaN
vertices to shapely, which raises
GEOSException: IllegalArgumentException: Points of LinearRing do not
form a closed linestring
Instead, only request the labels we actually want. In
_plot_cell_width(), that means draw_labels=['left', 'bottom']. In the
arrm10to60 and wc14 mesh plots, all four label sets were hidden, so
draw_labels=False.
Also drop the redundant fig.canvas.draw() and plt.tight_layout() from
_plot_cell_width(), since bbox_inches='tight' already crops the figure.
Removing tight_layout() alone is not sufficient: without the label fix,
the title is silently dropped and bbox_inches='tight' crops to a garbage
bounding box, saving only the colorbar.
List-valued draw_labels requires cartopy 0.22, so add that constraint.
Along the way, satisfy the pre-commit hooks on the arrm10to60 file:
isort reorders its imports and flake8 flags a pre-existing F523 (a
'{0} x {0}'.format(dlon, dlat) that never used dlat), now an f-string.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Collaborator
Author
TestingI'm running the EC30to60 grid through its paces in: The |
The switch from conda to pixi means the `conda` command is no longer available, so getting package versions for MPAS mesh metadata with `conda list` fails with a `FileNotFoundError`. Instead, look up conda package records in the environment's `conda-meta` directory, falling back on python package metadata for packages installed with pip (namely compass itself). Also, JIGSAW is now built as part of the `jigsawpy` package, so the two share a version. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Creating gridline labels with draw_labels=True and then hiding some of them (gl.top_labels = False, etc.) confuses cartopy's title placement. GeoAxes._update_title_position() scans gl.top_label_artists whenever gl.geo_labels is true (the default), so the hidden top labels are still included. During a draw, their tight bounding boxes are infinite, so the title ends up at y = inf and the axes tight bounding box becomes non-finite.
The NaN then cascades: tight_layout() gives the axes a NaN position, the "geo" spine path becomes all NaN, and cartopy's gridliner hands NaN vertices to shapely, which raises
Instead, only request the labels we actually want. In _plot_cell_width(), that means draw_labels=['left', 'bottom']. In the arrm10to60 and wc14 mesh plots, all four label sets were hidden, so draw_labels=False.
Also drop the redundant fig.canvas.draw() and plt.tight_layout() from _plot_cell_width(), since bbox_inches='tight' already crops the figure. Removing tight_layout() alone is not sufficient: without the label fix, the title is silently dropped and bbox_inches='tight' crops to a garbage bounding box, saving only the colorbar.
List-valued draw_labels requires cartopy 0.22, so add that constraint.
Along the way, satisfy the pre-commit hooks on the arrm10to60 file: isort reorders its imports and flake8 flags a pre-existing F523 (a '{0} x {0}'.format(dlon, dlat) that never used dlat), now an f-string.
This merge also fixes an unrelated provenance issue caused by the transition from conda to pixi.
Checklist
Testingin this PR) any testing that was used to verify the changes