mollview: use matplotlib colormaps and change background color

陌路散爱 提交于 2019-12-22 08:16:54

问题


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


回答1:


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



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/34023932/mollview-use-matplotlib-colormaps-and-change-background-color

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