在PyPlot中更新图像

时间:2013-02-20 00:31:49

标签: python graph matplotlib

下面是我的代码,我要做的就是更新图表上的点。我不想要绘制两条线,我一次只想要一条线。请帮忙

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 个答案:

答案 0 :(得分: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")