我正在尝试找到一种在matplotlib中动态删除子图的方法。我看到它们有一个remove方法,但是我遇到了错误。NotImplementedError: cannot remove artist 我很惊讶地发现这个在任何地方都找不到。有人知道怎么做吗?from matplotlib import pyplot as plt fig, axs = plt.subplots(1,3) axs[0].plot([1,2],[3,4]) axs[2].plot([0,1],[2,3]) plt.draw() plt.tight_layout()
使用fig.delaxes或plt.delaxes来移除不需要的子图。fig, axs = plt.subplots(1,3) axs[0].plot([1,2],[3,4]) axs[2].plot([0,1],[2,3]) fig.delaxes(axs[1]) plt.draw() plt.tight_layout()