在matplotlib子图中绘制比指定要少的图表

11
fig, ax = plt.subplots(3, 3, sharex='col', squeeze=False, figsize=(20, 10))

我想绘制7个子图,并使用上面的命令。但是它创建了9个图(包括2个空的)。我该如何确保只绘制7个图?

1个回答

9
import matplotlib.pyplot as plt

fig, axs  = plt.subplots(3,3)
fig.delaxes(axs[-1, -1])
fig.delaxes(axs[-1, -2])

plt.show()

enter image description here


谢谢@Serenity,[-1,-1]和[-2,-2]是什么? - user308827
1
您有一个3x3的子图网格。我设置了子图的坐标以删除它们(这是最后两个子图)。 - Serenity

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接