簡體   English   中英

如何檢查matplotlib中的子圖是否為空

[英]How to check if a subplot is empty in matplotlib

我在 matplotlib 中創建了幾個子圖:

fig, axes = plt.subplots(2, 2, figsize=(100, 85))
axes = axes.flatten()
'Other code for populating the subplots'

我想刪除最后一個情節,如果它是空的。 我試過這個代碼:

if axes[-1] is None:
    axes[-1].set_visible(False)

問題是軸元素是AxesSubplot類型的AxesSubplot

print(axes.flat[-1])

AxesSubplot(0.547727,0.125;0.352273x0.343182)

我該如何解決問題?

解決了:

if not axes[-1].lines: axes[-1].set_visible(False)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM