mollview: use matplotlib colormaps and change background color

眉间皱痕 提交于 2019-12-05 14:20:17

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()

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')

What you see is not an unexpected background colour. The colormap you use makes the lowest value in your plot appear blue. Since the stuff around you circular thing seems to be zero, this appears blue in the figure. Try using a colormap that is white at zero.

Update ~/anaconda3/lib/python3.7/site-packages/healpy/projaxes.py:

Replace all newcm.set_bad("gray") to newcm.set_bad((1, 1, 1, 1)).

In the example below, I have updated it to newcm.set_bad((0, 0, 0, .9)) to highlight how it works.

@tmdavison's answer doesn't work for customized normalization function. But the edit above would.

from healpy import mollview
from pylab import arange, show, cm, Normalize
m = arange(768)

mollview(m, cmap=cm.bwr, norm=Normalize(vmin=0, vmax=768))
show()

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!