Skip to content
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

Cartopy 0.24 throws a TypeError when saving with bbox_inches="tight" #2464

Closed
jfrost-mo opened this issue Oct 29, 2024 · 7 comments
Closed

Comments

@jfrost-mo
Copy link

jfrost-mo commented Oct 29, 2024

Description

Crash when plotting with bbox_inches="tight" in cartopy v0.24.0. This issue does not occur in v0.23, and I've traced it down to 454567a as the cause.

Code to reproduce

https://github.com/MetOffice/CSET/blob/adad8cc2341607e9fcfe796271368732201b75fc/tests/operators/test_plots.py#L74-L80

which runs

https://github.com/MetOffice/CSET/blob/adad8cc2341607e9fcfe796271368732201b75fc/src/CSET/operators/plot.py#L187-L279

Traceback

tests/operators/test_plots.py::test_spatial_pcolormesh_plot FAILED                                                                                                     [100%]

================================================================================== FAILURES ==================================================================================
________________________________________________________________________ test_spatial_pcolormesh_plot ________________________________________________________________________

cube = <iris 'Cube' of air_temperature / (K) (time: 3; grid_latitude: 17; grid_longitude: 13)>
tmp_working_dir = PosixPath('/var/tmp/pytest-of-jfrost/pytest-889/test_spatial_pcolormesh_plot0')

    def test_spatial_pcolormesh_plot(cube, tmp_working_dir):
        """Plot spatial pcolormesh plot of instant air temp."""
        # Remove realization coord to increase coverage, and as its not needed.
        cube.remove_coord("realization")
        cube_2d = cube.slices_over("time").next()
>       plot.spatial_pcolormesh_plot(cube_2d, filename="plot")

/net/home/h02/jfrost/Projects/CSET/tests/operators/test_plots.py:79: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/net/home/h02/jfrost/Projects/CSET/src/CSET/operators/plot.py:894: in spatial_pcolormesh_plot
    _spatial_plot("pcolormesh", cube, filename, sequence_coordinate, stamp_coordinate)
/net/home/h02/jfrost/Projects/CSET/src/CSET/operators/plot.py:783: in _spatial_plot
    plotting_func(
/net/home/h02/jfrost/Projects/CSET/src/CSET/operators/plot.py:277: in _plot_and_save_spatial_plot
    fig.savefig(filename, bbox_inches="tight", dpi=_get_plot_resolution())
/tmp/persistent/conda/envs/cset-test/lib/python3.12/site-packages/matplotlib/figure.py:3395: in savefig
    self.canvas.print_figure(fname, **kwargs)
/tmp/persistent/conda/envs/cset-test/lib/python3.12/site-packages/matplotlib/backend_bases.py:2175: in print_figure
    self.figure.draw(renderer)
/tmp/persistent/conda/envs/cset-test/lib/python3.12/site-packages/matplotlib/artist.py:95: in draw_wrapper
    result = draw(artist, renderer, *args, **kwargs)
/tmp/persistent/conda/envs/cset-test/lib/python3.12/site-packages/matplotlib/artist.py:72: in draw_wrapper
    return draw(artist, renderer)
/tmp/persistent/conda/envs/cset-test/lib/python3.12/site-packages/matplotlib/figure.py:3162: in draw
    mimage._draw_list_compositing_images(
/tmp/persistent/conda/envs/cset-test/lib/python3.12/site-packages/matplotlib/image.py:132: in _draw_list_compositing_images
    a.draw(renderer)
/tmp/persistent/conda/envs/cset-test/lib/python3.12/site-packages/matplotlib/artist.py:72: in draw_wrapper
    return draw(artist, renderer)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <_GeoAxesPatched: title={'center': 'Untitled | 2022-09-21 03:00:00'}>, renderer = <matplotlib.backends.backend_agg.RendererAgg object at 0x2b336e9530e0>, kwargs = {}

    @matplotlib.artist.allow_rasterization
    def draw(self, renderer=None, **kwargs):
        """
        Extend the standard behaviour of :func:`matplotlib.axes.Axes.draw`.
    
        Draw image factory results before invoking standard Matplotlib drawing.
        A global range is used if no limits have yet been set.
        """
        # Shared processing steps
>       self._draw_preprocess()
E       TypeError: _GeoAxesPatched._draw_preprocess() missing 1 required positional argument: 'renderer'

/net/home/h02/jfrost/Projects/cartopy/lib/cartopy/mpl/geoaxes.py:494: TypeError
========================================================================== short test summary info ===========================================================================
FAILED tests/operators/test_plots.py::test_spatial_pcolormesh_plot - TypeError: _GeoAxesPatched._draw_preprocess() missing 1 required positional argument: 'renderer'

Full environment definition

Operating system

Linux (RHEL 7)

Cartopy version

0.24.0

Conda list

https://github.com/MetOffice/CSET/blob/adad8cc2341607e9fcfe796271368732201b75fc/requirements/locks/py312-lock-linux-64.txt

@greglucas
Copy link
Contributor

What is _GeoAxesPatched? That looks to me like it is overriding a private method _draw_preprocess() and that private method is requiring the renderer argument. I'm not sure this is an issue in Cartopy, but rather with the GeoAxesPatched code.

@jfrost-mo
Copy link
Author

I suspect it is the iris patch referred to in this issue: SciTools/iris#5977

@jfrost-mo
Copy link
Author

Preposed fix: #2465

@rcomer
Copy link
Member

rcomer commented Oct 29, 2024

This will be fixed in the next version of Iris (for which the rc just went out).
SciTools/iris#6171

@jfrost-mo
Copy link
Author

I'll test this afternoon.

@jfrost-mo
Copy link
Author

Tested now with iris 3.11.0rc0 and it fixes this issue.

@QuLogic
Copy link
Member

QuLogic commented Oct 31, 2024

Seems like this is not a Cartopy bug.

@QuLogic QuLogic closed this as not planned Won't fix, can't repro, duplicate, stale Oct 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants