color_indices = (values - np.min(values)) / (np.max(values) - np.min(values))
im[:, (i), :] = cmap(color_indices)
im2 = im.copy()
for i, name in enumerate(df.T.columns):
    values = np.array(df.T[name])
print(values)
sorting = np.argsort(values)
print(('sorting', sorting))
im2[(i), ::-1, :] = im[(i), (sorting), :]
plt.imshow(im2, interpolation='nearest')
plt.grid(False)
plt.show()
Plotting sorted heatmap keeping (x,y) value colors