matplotlib 및 cartopy의 tight_layout 문제

Oct 14 2020

최근에 Matplotlib 3.3.1로 전환했고 이전 스크립트가 불평하기 시작했습니다. 카르 토피 문제라고 생각합니다. 다음은 재현 가능한 최소 예입니다.

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

이 문제를 해결하기위한 제안 사항이 있습니까?

여기에 오류 메시지를 복사합니다.

역 추적 (가장 최근 호출 마지막) :

plt.tight_layout ()의 파일 "", 4 행

파일 "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, tight_layout 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, 래퍼 return func (* inner_args, ** inner_kwargs)

파일 "C : \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ matplotlib \ figure.py", 2613 행, tight_layout 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 return self.get_path (). get_extents (self.get_transform ())

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

파일 "C : \ Users \ Vinod \ anaconda3 \ lib \ site-packages \ numpy \ core_methods.py", 라인 43, in _amin return umr_minimum (a, axis, None, out, keepdims, initial, where)

ValueError : ID가없는 축소 작업 최소값에 대한 크기가 0 인 배열

답변

1 jwalton Oct 14 2020 at 21:07

이것은 알려진 문제이며 다음에서 해결되었습니다. https://github.com/SciTools/cartopy/issues/1207. (최신 버전의 cartopy가 있는지 확인하면이 문제가 해결 될 수 있습니다.)

한편,에 전화하기 fig.canvas.draw()전에에 전화를 걸 수 있다는 해결 방법이 있습니다 plt.tight_layout().