1

I'm looking for method that will allow me to update axis when my script is running but, I couldn't find it. For example:

import matplotlib.pyplot as plt

x = (1,2)
y = (1,2)

plt.plot(x,y, 'r-')
plt.show()

#here during run of program I want to clear axis with help of plt.cla() and update it 
#new one

# x = (2,4)
# y = (2,4)
#plt.plot(x,y, 'b-')

1 Answer 1

2

To get the functionality you want you probably want to set matplotlib to interactive mode:

plt.ion()

Then call draw to update. For example:

import numpy
import time
x = (1,2)
y = (1,2)
plt.ion()
plt.plot(x,y, 'r-')
plt.draw()

for i in range(100):
   print i
   time.sleep(1)
   plt.cla()
   y = (numpy.random.normal(), numpy.random.normal())
   plt.plot(x,y, 'r-')
   plt.draw()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.