# USE
#    From a shell prompt, enter:
#          > python matplotlib-slow.py


_script_  = 'matplotlib.pyplot.pcolor-slow'
_purpose_ = 'demonstrate long execution time of matplotlib.pyplot.pcolor'
_author_  = 'jim.vickroy@noaa.gov'


import numpy             # http://numpy.scipy.org/
import matplotlib        # http://matplotlib.sourceforge.net/
matplotlib.use('Agg')    # http://matplotlib.sourceforge.net/backends.html -- probably the fastest, non-GUI, rendering backend
import matplotlib.pyplot # http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot
import logging, sys


# configuring the logger ...
logging.basicConfig(level=logging.DEBUG, format='[%(asctime)s] [%(levelname)-8s] [line #%(lineno)3d] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
log = logging.getLogger() # root logger


log.debug('Python version:     %s' % sys.version)
log.debug('numpy version:      %s' % numpy.__version__)
log.debug('matplotlib version: %s' % matplotlib.__version__)


# defining the array to be plotted ...
rows  = columns = 512
shape = rows,columns
data  = numpy.zeros(shape, dtype=float)


# creating the image of the array ...
xi, yi = numpy.arange(rows), numpy.arange(columns)
XI, YI = numpy.meshgrid(xi, yi)
log.debug('executing matplotlib.pyplot.subplot()')
matplotlib.pyplot.subplot(1, 1, 1)
log.debug('executing matplotlib.pyplot.pcolor()')
matplotlib.pyplot.pcolor(XI, YI, data, cmap=matplotlib.cm.jet)
log.debug('executing matplotlib.pyplot.colorbar()')
matplotlib.pyplot.colorbar()
im = matplotlib.pyplot.imshow(data, interpolation='bilinear', cmap=matplotlib.cm.jet, origin='upper', extent=[0,rows, 0,columns])
#    matplotlib.pyplot.show()
log.debug('executing matplotlib.pyplot.savefig()')
matplotlib.pyplot.savefig('%s.png' % _script_)
log.debug('executing matplotlib.pyplot.close()')
matplotlib.pyplot.close()
