Kyle Pearson
Kyle Pearson

Reputation: 13

Update image in PyPlot

Below is my code, all I am looking to do is update the points on the graph. I do not want two lines to be graphed, I just want one line at a time. Please help

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")

Upvotes: 1

Views: 360

Answers (1)

wim
wim

Reputation: 362557

You need to grab a handle on the return value of plot, and then use set_data later.

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")

Upvotes: 1

Related Questions