[英]Issue with tight_layout with matplotlib and cartopy
我最近切換到 Matplotlib 3.3.1 並且我的舊腳本開始抱怨。 我想這是cartopy的問題。 這是一個最小的可重現示例
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()
有什么建議可以解決這個問題嗎?
這里我復制錯誤信息:
回溯(最近一次調用最后一次):
文件“”,第 4 行,在 plt.tight_layout() 中
文件“C:\\Users\\Vinod\\anaconda3\\lib\\site-packages\\matplotlib\\cbook\\deprecation.py”,第 451 行,包裝器返回 func(*args, **kwargs)
文件“C:\\Users\\Vinod\\anaconda3\\lib\\site-packages\\matplotlib\\pyplot.py”,第 1490 行,緊縮布局 gcf().tight_layout(pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect )
文件“C:\\Users\\Vinod\\anaconda3\\lib\\site-packages\\matplotlib\\cbook\\deprecation.py”,第 411 行,包裝器返回 func(*inner_args, **inner_kwargs)
文件“C:\\Users\\Vinod\\anaconda3\\lib\\site-packages\\matplotlib\\figure.py”,第 2613 行,緊縮布局 kwargs = get_tight_layout_figure(
文件“C:\\Users\\Vinod\\anaconda3\\lib\\site-packages\\matplotlib\\tight_layout.py”,第 303 行,在 get_tight_layout_figure kwargs = auto_adjust_subplotpars(fig, renderer,
文件“C:\\Users\\Vinod\\anaconda3\\lib\\site-packages\\matplotlib\\tight_layout.py”,第 84 行,在 auto_adjust_subplotpars bb += [ax.get_tightbbox(renderer, for_layout_only=True)]
文件“C:\\Users\\Vinod\\anaconda3\\lib\\site-packages\\matplotlib\\axes_base.py”,第 4203 行,在 get_tightbbox bbox = a.get_tightbbox(renderer)
文件“C:\\Users\\Vinod\\anaconda3\\lib\\site-packages\\matplotlib\\artist.py”,第 278 行,在 get_tightbbox bbox = self.get_window_extent(renderer)
文件“C:\\Users\\Vinod\\anaconda3\\lib\\site-packages\\matplotlib\\patches.py”,第 598 行,在 get_window_extent 中返回 self.get_path().get_extents(self.get_transform())
文件“C:\\Users\\Vinod\\anaconda3\\lib\\site-packages\\matplotlib\\path.py”,第 603 行,在 get_extents 中返回 Bbox([xys.min(axis=0), xys.max(axis=0) ])
文件“C:\\Users\\Vinod\\anaconda3\\lib\\site-packages\\numpy\\core_methods.py”,第 43 行,在 _amin 中 return umr_minimum(a, axis, None, out, keepdims, initial, where)
ValueError:零大小數組到沒有標識的最小化操作
這是一個已知問題,已在: https : //github.com/SciTools/cartopy/issues/1207 中得到解決。 (確保您擁有最新版本的 cartopy 可能會解決此問題)。
同時,作為一種解決方法,您可以在調用fig.canvas.draw()
之前調用plt.tight_layout()
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.