如何确定subplot(AxesSubplot)是否为空?我想停用空子图的空轴并删除完全空行.
例如,在该图中,仅填充了两个子图,其余的子图是空的.
import matplotlib.pyplot as plt
# create figure wit 3 rows and 7 cols; don't squeeze is it one list
fig, axes = plt.subplots(3, 7, squeeze=False)
x = [1,2]
y = [3,4]
# plot stuff only in two SubAxes; other axes are empty
axes[0][1].plot(x, y)
axes[1][2].plot(x, y)
# save figure
plt.savefig('image.png')
Run Code Online (Sandbox Code Playgroud)
注意:必须设置squeeze为False.
基本上我想要一个稀疏的人物.行中的某些子图可以为空,但应将其取消激活(不能显示任何轴).必须删除完全空行,不得将其设置为不可见.