我正在尝试找出一种删除(动态)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()
![enter image description here](https://i.stack.imgur.com/UoBJ1.png)
Use fig.delaxes or 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()
![enter image description here](https://i.stack.imgur.com/GQSgJ.png)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)