def truncate_colormap(cmap, minval=<NUM_LIT:0.0>, maxval=<NUM_LIT:1.0>, n=<NUM_LIT>):
cmap = get_cmap(cmap)<EOL>name = "<STR_LIT>" % (cmap.name, minval, maxval)<EOL>return colors.LinearSegmentedColormap.from_list(<EOL>name, cmap(np.linspace(minval, maxval, n)))<EOL>
Truncates a colormap, such that the new colormap consists of
``cmap[minval:maxval]``.

If maxval is larger than minval, the truncated colormap will be reversed.

Args:

    cmap (colormap): Colormap to be truncated

    minval (float): Lower bound. Should be a float betwee 0 and 1.

    maxval (float): Upper bound. Should be a float between 0 and 1

    n (int): Number of colormap steps. Default is ``256``.

Returns:

    colormap: A matplotlib colormap

http://stackoverflow.com/questions/18926031/how-to-extract-a-subset-of-a-colormap-as-a-new-colormap-in-matplotlib