#NEWLINE# def colorize_subsets( subsets , cmap , lo = 0 , hi = 1 ) : #NEWLINE# #INDENT# 'Re-color a list of subsets according to a colormap\n\n    :param subsets: List of subsets\n    :param cmap: Matplotlib colormap instance\n    :param lo: Start location in colormap. 0-1. Defaults to 0\n    :param hi: End location in colormap. 0-1. Defaults to 1\n\n    The colormap will be sampled at `len(subsets)` even intervals\n    between `lo` and `hi`. The color at the `ith` interval will be\n    applied to `subsets[i]`\n    ' #NEWLINE# from matplotlib import cm #NEWLINE# sm = cm . ScalarMappable ( cmap = cmap ) #NEWLINE# sm . norm . vmin = 0 #NEWLINE# sm . norm . vmax = 1 #NEWLINE# vals = np . linspace ( lo , hi , len ( subsets ) ) #NEWLINE# rgbas = sm . to_rgba ( vals ) #NEWLINE# for ( color , subset ) in zip ( rgbas , subsets ) : #NEWLINE# #INDENT# ( r , g , b , a ) = color #NEWLINE# r = int ( ( 255 * r ) ) #NEWLINE# g = int ( ( 255 * g ) ) #NEWLINE# b = int ( ( 255 * b ) ) #NEWLINE# subset . style . color = ( '#%2.2x%2.2x%2.2x' % ( r , g , b ) )