Python 如何检查matplotlib中的子批次是否为空
我在matplotlib中创建了几个子地块,如下所示:Python 如何检查matplotlib中的子批次是否为空,python,matplotlib,subplot,Python,Matplotlib,Subplot,我在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的对象:
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
的对象:
print(axes.flat[-1])
AxesSubplot(0.547727,0.125;0.352273x0.343182)
如何解决此问题?已解决:
if not axes[-1].lines: axes[-1].set_visible(False)