Graphing a colored grid in python
Question: I am trying to create a 2D plot in python where the horizontal axis is split
into a number of intervals or columns and the color of each column varies
along the vertical axis.

The color of each interval depends on the value of a periodic function of
time. For simplicity, let's say these values range between 0 and 1. Then
values closer to 1 should be dark red and values close to 0 should be dark
blue for example (the actual colors don't really matter).

Here is an example of what the plot should look like:

[![Example of
plot](http://i.stack.imgur.com/XxWUL.png)](http://i.stack.imgur.com/XxWUL.png)

Is there a way to do this in Python using matplotlib?


Answer: This is really just displaying an image. You can do this with `imshow`.

    
    
    import matplotlib.pyplot as plt
    
    import numpy as np
    
    # Just some example data (random)
    data = np.random.rand(10,5)
    
    rows,cols = data.shape
    
    plt.imshow(data, interpolation='nearest', 
                     extent=[0.5, 0.5+cols, 0.5, 0.5+rows],
                     cmap='bwr')
    

[![enter image description
here](http://i.stack.imgur.com/hLAQm.png)](http://i.stack.imgur.com/hLAQm.png)

