mollview:使用matplotlib颜色图并更改背景颜色 [英] mollview: use matplotlib colormaps and change background color

查看:58
本文介绍了mollview:使用matplotlib颜色图并更改背景颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 healpy.mollview 上使用其他颜色图我成功使用此代码

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

推荐答案

healpy 似乎对其默认颜色图进行了修改,以更改颜色超出范围时发生的情况.因此,在将 cm.bwr 赋予 healpy 之前,我们需要做同样的事情.我们可以使用 cmap.set_under('w') 将颜色设置为白色.

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.

对我来说这似乎是 healpy 中的一个错误,因为这会影响您尝试使用的大多数颜色图.

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

为了完全模仿 healpy 对其默认颜色图所做的事情(它使用 jet),我们需要设置 over, bad 值下.这是相关函数来自healpy/code> github.

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

这篇关于mollview:使用matplotlib颜色图并更改背景颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆