""" make a contour plot with the levels specified,
    and with the colormap generated automatically from a list of colors
    including specification of colors for values above and below the
    specified levels. 
"""
from scipy.io import read_array
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

# loading your special data
m = read_array("v.matrix")
X = np.reshape(m[:, 0], (51, 51))
Y = np.reshape(m[:, 1], (51, 51))
Z = np.reshape(m[:, 2], (51, 51))

# or using just some random data
# X, Y = np.meshgrid(np.arange(51), np.arange(51))
# Z = 3.0*np.random.random((51, 51))

ax = plt.subplot(111, autoscale_on=False, xlim=(0, 50), ylim=(0, 50))

# set up a listed colormap (colors between the later defined bounds),
# which could be also achieved by passing 'colors=('r', 'g', 'b')' to
# contourf, but than one can not specifiy 'over' and 'under' color
# (at least up to my knowledge)
cmap = matplotlib.colors.ListedColormap(['r', 'g', 'b'])
cmap.set_over('cyan')                # specify color for larger 
cmap.set_under('yellow')             # and smaller values

# levels or boundaries of your colormap (len(bounds) = len(colorlist) + 1 !)
bounds = [1.0, 1.5, 2.0, 2.5]
norm = matplotlib.colors.BoundaryNorm(bounds, cmap.N)

# plot contour lines with filling in between:
my_contourf = plt.contourf(X, Y, Z, bounds,
                           cmap=cmap, norm=norm, extend='both')

# and some thicker contourlines
plt.contour(X, Y, Z, bounds, colors = ('black',), linewidths = (2,))

# add a colorbar to the figure
plt.colorbar(my_contourf, fraction=0.10, aspect=3, extend='both',
             ticks=bounds)

plt.show()
