def color_mapping(arr, cmap): sm = ScalarMappable(cmap=cmap) sm.set_array(arr) sm.autoscale() return map(rgb2hex, sm.to_rgba(arr))