1

I am trying to plot some values using a seaborn heatmap, and my values range from 0 to 1, but I am mainly interested in the variation from 0 to 0.05. I was looking for a way to have the range 0-0.05 in the color bar be as big as the range 0.05 - 1, with either both ranges being different color gradients or the bottom region being a gradient, and top being one color.

So far I managed to use DivergingNorm(vmin=0, vcenter=0.05,vmax=1) to get the following plot

I would like to center the 0.05 in the middle of the bar and shrink the range of 0.05-1 into the top half. It's my first time posting, so I am not very sure what other material might make it easier for you to help me :)

  • Maybe you could try a [logarithmic norm](https://matplotlib.org/3.1.1/tutorials/colors/colormapnorms.html#logarithmic) ? – JohanC Apr 04 '20 at 14:22
  • How would that solve the problem? – Mohamed Ayman Aly Apr 04 '20 at 15:53
  • A logarithmic norm enlarges the region for the small number. The white color will stay nicely in the center. And the ticks for the colorbar will have logical distances. You should set vmin to a small number, but larger than zero. Whether it solves your problem, is hard to say, depending on the exact data and their distribution. Trying could give some extra insights. – JohanC Apr 04 '20 at 16:24
  • Yes, it expands the region for small numbers, but as far as I am aware there is not a way I can esnure the 0.05 value is exactly the central (white) value in a log scale. However, I am not experienceed in mpl colorbars so I could be very wrong :) Thank you for yout help! – Mohamed Ayman Aly Apr 04 '20 at 18:41
  • Actually found a very useful implmentation of a midpoint to a lognorm which solved my problem here https://stackoverflow.com/questions/48625475/python-shifted-logarithmic-colorbar-white-color-offset-to-center. Thanks a lot @JohanC – Mohamed Ayman Aly Apr 04 '20 at 19:00

0 Answers0