如何確定子圖(AxesSubplot
)是否爲空?我想停用空子圖的空軸並刪除完全空行。刪除matplotlib中的空子圖圖
例如,在此圖中只填充了兩個子圖,其餘子圖都是空的。
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')
注:必須設置squeeze
到False
。
基本上我想要一個稀疏的數字。一些行中的子圖可以是空的,但是它們應該被禁用(不必顯示軸)。完全空行必須刪除,不能設置爲不可見。
你可以使用subplot2grid? – DavidG
我認爲這將是可能的,但它如何解決我的問題確定空子圖? – hotsplots
查看我的回答,看看它是否適用於您的問題 – DavidG