matplotlibhealpy

mollview: use matplotlib colormaps and change background color


I'm trying to use others colormaps on healpy.mollview I succeded with this code

from healpy import mollview
from pylab import arange, show, cm
m = arange(768)
mollview(m, cmap=cm.bwr)
show()

but I get an unexpected blue background and there is no way I can set it to white


Solution

  • healpy seems to make a modification to its default colormap to change what happens when the color is out of range. So, we need to do the same before we give cm.bwr to healpy. We can do this with cmap.set_under('w') to set the color to white.

    This seems like a bug in healpy to me, since this will affect most colormaps you try to use.

    from healpy import mollview,cartview
    from pylab import arange, show, cm
    
    cmap = cm.bwr
    cmap.set_under('w')
    
    m = arange(768)
    mollview(m, cmap=cmap)
    show()
    

    enter image description here

    To fully mimic what healpy does to its default colormap (it uses jet), we need to set the over, under and bad values. Here's the relevant function from the healpy github.

    cmap=cm.bwr
    cmap.set_over(cmap(1.0))
    cmap.set_under('w')
    cmap.set_bad('gray')