1

I would like to plot my intermediate results and want to see how is the algorithm progressing. I have posted a demo code too. Lets say my algorithm goes for 20 epochs and I want to plot the result of every epoch in a same file. I tried with following demo code. But I can not see any plot on a.png.

Could someone help me how could I do it?

import  matplotlib.pylab  as plt 
import numpy as np


for i in range(20):
  y = np.random.random()
  plt.plot(i, y)
  plt.savefig('a.png')
1
  • Grab a refernce to the Line2D object and use set_data Commented Jul 21, 2015 at 19:06

1 Answer 1

1

You have to provide the whole history in your variables e.g. as a list:

import matplotlib.pylab as plt 
import numpy as np

# creates two lists with the same length
x = range(20)
y = [0] * 20
for i in x:
  y.insert(i, np.random.random())
  plt.plot(x, y)
  plt.savefig('plot_%d.png' % i)
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.