I found the general approach to set the null pixels to white is to use a lognorm colormap.
Is there a way to use a linear colormap but still set null pixels to white?
Thanks!
In new versions of matplotlib you can simply use cmin = 1
, i.e.
plt.hist2d(x,y,cmin = 1)
will set all bins with fewer than one count to nan, i.e. nonvisible. If your background is white (default) then these bins will appear white. But they will change wil the background.
You can use '.set_under':
import matplotlib.pyplot as plt
my_cmap = plt.cm.jet
my_cmap.set_under('w',1)
...
plt.hist2d( ..., cmap = my_cmap)
This sets all values under 1 (i.e. the lowest count) to 'w' (=white).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With