![](/img/trans.png)
[英]In Python with Matplotlib how to check if a subplot is empty in the figure
[英]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.