def mpl_palette(name, n_colors=6):
 brewer_qual_pals = {'Accent': 8, 'Dark2': 8, 'Paired': 12, 'Pastel1': 9, 'Pastel2': 8, 'Set1': 9, 'Set2': 8, 'Set3': 12}
 if name.endswith('_d'):
  pal = ['#333333']
  pal.extend(color_palette(name.replace('_d', '_r'), 2))
  cmap = blend_palette(pal, n_colors, as_cmap=True)
 else:
  cmap = getattr(mpl.cm, name)
 if (name in brewer_qual_pals):
  bins = np.linspace(0, 1, brewer_qual_pals[name])[:n_colors]
 else:
  bins = np.linspace(0, 1, (n_colors + 2))[1:(-1)]
 palette = list(map(tuple, cmap(bins)[:, :3]))
 return palette

def mpl_palette ( name , n_colors = 6 ) : brewer_qual_pals = { 'Accent' : 8 , 'Dark2' : 8 , 'Paired' : 12 , 'Pastel1' : 9 , 'Pastel2' : 8 , 'Set1' : 9 , 'Set2' : 8 , 'Set3' : 12 } if name . endswith ( '_d' ) : pal = [ '#333333' ] pal . extend ( color_palette ( name . replace ( '_d' , '_r' ) , 2 ) ) cmap = blend_palette ( pal , n_colors , as_cmap = True ) else : cmap = getattr ( mpl . cm , name ) if ( name in brewer_qual_pals ) : bins = np . linspace ( 0 , 1 , brewer_qual_pals [ name ] ) [ : n_colors ] else : bins = np . linspace ( 0 , 1 , ( n_colors + 2 ) ) [ 1 : ( - 1 ) ] palette = list ( map ( tuple , cmap ( bins ) [ : , : 3 ] ) ) return palette
return discrete colors from a matplotlib palette .