I am trying to loosely replicate the below colorbar in matplotlib:
I cannot seem to make the colorbar similar.
Here is what I have tried so far:
I defined the cvals & colors according to this post:
cvals = [-30 , -25 , -20 , -15 , -10 , -7.5 , -5 , -2.5 , 0 , 2.5 , 5 , 7.5 , 10 , 15 , 20 , 25 , 30]
colors = ["#000080", "#000080" , "#3F00FF" , "#1F51FF" , "#0096FF" , "#6495ED" , "#00FFFF" , "white" , "white" , "white" , "#FAA0A0" , "#F88379" , "#FA8072" , "#FA5F55" , "#FF2400" , "#80461B" , "#7C3030"]
I then also according to the above post, I did the following:
norm=plt.Normalize(min(cvals),max(cvals))
tuples = list(zip(map(norm,cvals), colors))
cmap = matplotlib.colors.LinearSegmentedColormap.from_list("", tuples)
Then in the color bar I used
cb = fig.colorbar(
boundaries = cvals ,
spacing = 'uniform' ,
ticks = cvals ,
drawedges = False
)
The colorbar looks like this:
I am not worried about the text being outside the bar or that the colors are not quite the same but I cannot seem to get the white in the right spots or make the bar display from -30 to 30. I am also worried the graph may not display the proper coloring based on the bins.
Any help would be appreciated.