Problem mit tight_layout mit matplotlib und cartopy

Oct 14 2020

Ich bin kürzlich zu Matplotlib 3.3.1 gewechselt und mein altes Skript beginnt sich zu beschweren. Ich denke, es ist ein Problem mit der Kartusche. Hier ist ein minimal reproduzierbares Beispiel

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()

Irgendwelche Vorschläge zur Behebung dieses Problems?

Hier kopiere ich die Fehlermeldung:

Traceback (letzter Anruf zuletzt):

Datei "", Zeile 4, in plt.tight_layout ()

Datei "C: \ Benutzer \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ cbook \ deprecation.py", Zeile 451, in Wrapper-Rückgabefunktion (* args, ** kwargs)

Datei "C: \ Benutzer \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ pyplot.py", Zeile 1490, in dem engen Layout gcf (). Das enge Layout (pad = pad, h_pad = h_pad, w_pad = w_pad, rect = rect )

Datei "C: \ Benutzer \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ cbook \ deprecation.py", Zeile 411, in Wrapper-Rückgabefunktion (* inner_args, ** inner_kwargs)

Datei "C: \ Benutzer \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ figure.py", Zeile 2613, in tight_layout kwargs = get_tight_layout_figure (

Datei "C: \ Benutzer \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ tight_layout.py", Zeile 303, in get_tight_layout_figure kwargs = auto_adjust_subplotpars (Abb., Renderer,

Datei "C: \ Benutzer \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ tight_layout.py", Zeile 84, in auto_adjust_subplotpars bb + = [ax.get_tightbbox (Renderer, for_layout_only = True)]

Datei "C: \ Benutzer \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ axes_base.py", Zeile 4203, in get_tightbbox bbox = a.get_tightbbox (Renderer)

Datei "C: \ Benutzer \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ artist.py", Zeile 278, in get_tightbbox bbox = self.get_window_extent (Renderer)

Die Datei "C: \ Benutzer \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ patches.py", Zeile 598, in get_window_extent gibt self.get_path () zurück. Get_extents (self.get_transform ())

Die Datei "C: \ Benutzer \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ path.py", Zeile 603, in get_extents gibt Bbox zurück ([xys.min (Achse = 0), xys.max (Achse = 0) ])

Datei "C: \ Benutzer \ Vinod \ anaconda3 \ lib \ site-packages \ numpy \ core_methods.py", Zeile 43, in _amin return umr_minimum (a, Achse, Keine, out, keepdims, initial, where)

ValueError: Array mit der Größe Null für das Minimum der Reduktionsoperation ohne Identität

Antworten

1 jwalton Oct 14 2020 at 21:07

Dies war ein bekanntes Problem und wurde behandelt in: https://github.com/SciTools/cartopy/issues/1207. (Wenn Sie sicherstellen, dass Sie über die neueste Version von cartopy verfügen, kann dieses Problem möglicherweise behoben werden.)

In der Zwischenzeit wurde als Problemumgehung festgestellt, dass Sie fig.canvas.draw()vor Ihrem Anruf einen Anruf tätigen können plt.tight_layout().