2013-02-20 67 views
1

下面是我的代码,我所要做的就是更新图上的点。我不想要两条线被绘制,我只需要一条线。请帮助更新PyPlot中的图像

import matplotlib.pyplot as plt 
x = [1,2,3,4] 
y = [1,4,9,16] 

plt.ion() 
plt.plot(x,y) 
var = raw_input("type enter to change") 
#update data some where here? 
plt.plot(y,x) 
plt.draw() 
var = raw_input("type enter to end") 

回答

1

你需要抢情节的返回值的句柄,然后用set_data以后。

import matplotlib.pyplot as plt 
x = [1,2,3,4] 
y = [1,4,9,16] 

plt.ion() 
h = plt.plot(x,y) 
plt.show() 
var = raw_input("type enter to change") 
#update data some where here? 
h[0].set_data(y,x) 
plt.show() 
var = raw_input("type enter to end")