Matplotlib - 从轴上移除东西

时间:2012-02-20 16:24:51

标签: python numpy matplotlib

我正在寻找方法或其他东西,这将允许我删除一个的东西(我知道cla()将清除整个),例如来自轴的行,类似于:

x = self.plt.plot([5*a,0],[0,5*b], color = 'black')
self.plt.draw()
#here I want to to remove x, calculate new position and draw again

一切都是以互动模式完成的。

1 个答案:

答案 0 :(得分:3)

br@ymir:~/sweethome/temp$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:57:41) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> plt.ion()
>>> l,=plt.plot([1,2,3],[4,5,6],'bo-')      # a figure pops up
>>> l.remove()                              # nothing happens
>>> plt.draw()                              # don't forget to redraw
>>> 

但是,如果您只想更改元素,则可以使用set_ydata(...)后跟draw()