0

sadly I could not find an answer to my question online. Essentially, I am trying to use a colorbar for a contourf plot that has closer spacing of the colors near zero (as I am interested in the small changes) and larger ranges for colors further away. The spacing should double for each new color (as see in the picture) and the colorbar should "extend" to both sides.

Any ideas or recommendations what I should

It seems like it should be the opposite of the matplotlib.colors.SymLogNorm function. enter image description here

This is what I tried so far but it does the opposite from what I want.

divnorm = colors.SymLogNorm(vmin=cbar_min, vmax=cbar_max, linthresh=10 ** (-5))

xr.plot.contourf(darray=var_c[ncount, :, :], ax=ax, cmap=colormap_sel, norm=divnorm, levels=levels, extend="both")
mosc9575
  • 5,618
  • 2
  • 9
  • 32
random__human
  • 99
  • 2
  • 9
  • 2
    Maybe https://stackoverflow.com/questions/35295075/define-custom-normalisation-function-in-matplotlib-when-using-plt-colorbar – Jody Klymak Oct 27 '21 at 14:49
  • Maybe `BoundaryNorm([-0.8, -0.4, -0.2, -0.1, 0.1, 0.2, 0.4, 0.8], ncolors=256)`? – JohanC Oct 27 '21 at 17:30
  • @JodyKlymak Ah thanks, I think this works!!! I could not find this stack overflow when I searched for it. – random__human Oct 27 '21 at 17:55
  • @JohanC Thanks for answering my question:) I ended up specifying the levels and using the PiecewiseNorm function they defined in https://stackoverflow.com/questions/35295075/define-custom-normalisation-function-in-matplotlib-when-using-plt-colorbar which seems to work – random__human Oct 27 '21 at 17:56

0 Answers0