Python 删除子图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14694501/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Delete a subplot
提问by Jeff
I'm trying to figure out a way of deleting (dynamically) subplots in matplotlib. I see they have a removemethod, but I get the error
我试图找出一种在 matplotlib 中删除(动态)子图的方法。我看到他们有一个remove方法,但我得到了错误
NotImplementedError: cannot remove artist
I'm surprised that I can't find this anywhere. Does anyone know how to do this?
我很惊讶我在任何地方都找不到这个。有谁知道如何做到这一点?
采纳答案by Jeff
Wow, ok well I feel really stupid :P
哇,好吧,我觉得真的很愚蠢:P
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])
fig.delaxes(axs[1])
plt.draw()
In case anyone else needs it.
万一其他人需要它。
回答by naught101
ax.set_visible(False)
will suffice in most cases.
在大多数情况下就足够了。

