Reputation: 53
I'm trying to do a contourf plot of the divergence of a vector field with python and then add a colorbar to this plot. My levels are intended to be symmetric around zero from -0.01 to 0.01.
This is a part of my code:
div_levs = [-0.01, -0.005, -0.0025, 0.0025, 0.005, 0.01]
col = ['Blue', 'SteelBlue', 'White', 'Orange', 'Red']
c = plt.contourf(iwrf['x'], iwrf['y'], np.squeeze(iwrf['DIV'][ind_lev,:,:]),
levels=div_levs, colors=col, extend='both')
c.cmap.set_over('Magenta')
c.cmap.set_under('MidnightBlue')
bar = plt.colorbar(ticks=div_levs)
bar.set_label('1/s')
If I execute the python script it works, and everything gets drawn in the right way but the colormap is labeled with:
0.9900, 0.9950, 0.9975, 1.025, 1.0050, 1.0100
and on top of the colorbar a "-1" is displayed.
I've tried a lot, including setting the ticks of the colorbar after creating it, or setting the ticks in debug mode but nothing seems to change this behaviour.
Any ideas on this?
Upvotes: 5
Views: 1202