"""
    to compare velocity / time usage of
    (1) new plotting every time 'plot(x, y)'
    (2) setp(line, data=(x, y))
    (3) line.set_data((x, y))                     
    using matplotlib interactive mode ('ion()')
"""

import pylab
import numpy
import time
                                              # some data
x, y = numpy.linspace(0.0, 1.0, 1000), numpy.linspace(0.0, 1.0, 1000)
N = 150                                       # number of plot/setp-events

# initialization of a matplotlib figure, axes and labels
pylab.ion()
pylab.figure(0)
ax = pylab.axes()
pylab.xlabel('x')
pylab.ylabel('y')

T_1 = time.time()
                                              # using 'plot(x, y)'
for i in xrange(N):
    ax.lines = []
    pylab.plot(x, y, color='blue')
    pylab.draw()

T_2 = time.time()
                                              # using 'setp(line, data=(x, y))'
line, = pylab.plot([0], [0], color='blue')
for i in xrange(N):
    pylab.setp(line, data=(x, y))
    pylab.draw()

T_3 = time.time()
                                              # using 'line.set_data(x, y)'
line, = pylab.plot([0], [0], color='blue')
for i in xrange(N):
    line.set_data((x, y))
    pylab.draw()

T_4 = time.time()

pylab.ioff()

print " time >plot< = %.3f (my machine: 9.7)" % (T_2-T_1)
print " time >setp< = %.3f (my machine: 9.9)" % (T_3-T_2)
print " time >.set< = %.3f (my machine: 5.0)" % (T_4-T_3)

#pylab.show()
