Problème avec tight_layout avec matplotlib et cartopy

Oct 14 2020

Je suis récemment passé à Matplotlib 3.3.1 et mon ancien script commence à se plaindre. Je suppose que c'est un problème de cartopie. Voici un exemple minimum reproductible

import cartopy.crs as ccrs    
fig, ax = plt.subplots(2, 2,
                       subplot_kw=dict(projection=ccrs.PlateCarree()),
                      figsize=[12,7], sharex=True, sharey=True)
plt.tight_layout()

Une suggestion pour résoudre ce problème?

Ici, je copie le message d'erreur:

Traceback (dernier appel le plus récent):

Fichier "", ligne 4, dans plt.tight_layout ()

Fichier "C: \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ cbook \ deprecation.py", ligne 451, dans le wrapper return func (* args, ** kwargs)

Fichier "C: \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ pyplot.py", ligne 1490, dans tight_layout gcf (). Tight_layout (pad = pad, h_pad = h_pad, w_pad = w_pad, rect = rect )

Fichier "C: \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ cbook \ deprecation.py", ligne 411, dans le wrapper return func (* inner_args, ** inner_kwargs)

Fichier "C: \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ figure.py", ligne 2613, dans tight_layout kwargs = get_tight_layout_figure (

Fichier "C: \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ tight_layout.py", ligne 303, dans get_tight_layout_figure kwargs = auto_adjust_subplotpars (fig, renderer,

Fichier "C: \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ tight_layout.py", ligne 84, dans auto_adjust_subplotpars bb + = [ax.get_tightbbox (renderer, for_layout_only = True)]

Fichier "C: \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ axes_base.py", ligne 4203, dans get_tightbbox bbox = a.get_tightbbox (renderer)

Fichier "C: \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ artist.py", ligne 278, dans get_tightbbox bbox = self.get_window_extent (renderer)

Fichier "C: \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ patches.py", ligne 598, dans get_window_extent return self.get_path (). Get_extents (self.get_transform ())

Fichier "C: \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ path.py", ligne 603, dans get_extents return Bbox ([xys.min (axis = 0), xys.max (axis = 0) ])

Fichier "C: \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ numpy \ core_methods.py", ligne 43, dans _amin return umr_minimum (a, axis, None, out, keepdims, initial, where)

ValueError: tableau de taille zéro au minimum d'opération de réduction qui n'a pas d'identité

Réponses

1 jwalton Oct 14 2020 at 21:07

Il s'agissait d'un problème connu et a été résolu dans: https://github.com/SciTools/cartopy/issues/1207. (S'assurer que vous disposez de la dernière version de cartopy peut résoudre ce problème).

En attendant, comme solution de contournement, il a été noté que vous pouviez passer un appel fig.canvas.draw()avant votre appel plt.tight_layout().