0
votes

First, I normalize my data on [0,1], to assign the respective values to a color of the red spectrum.

reds = (data/data.max()).flatten()
rgb_data = np.array([(r,0,0)for r in reds]).reshape((x.max(),y.max(),3))

I create a colormap

my_cmap = mcolors.ListedColormap(rgb_data)
cax = ax.imshow(rgb_data)

The problem is that the colorbar

cbar = colorbar(cax)

spans also over colors with green and blue unequal to 0.

How can I customize it to span from black to deep red without going over green and blue?

1

1 Answers

0
votes

You had it almost right

cax = ax.imshow(rgb_data, cmap = my_cmap)

You defined your own colormap but you also have to pass it as an argument.