在 matplotlib 中定义颜色图的中点 [英] Defining the midpoint of a colormap in matplotlib

查看:39
本文介绍了在 matplotlib 中定义颜色图的中点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置颜色图的中间点,即我的数据从 -5 到 10,我希望零作为中间点.我认为这样做的方法是通过子类化 normalize 并使用规范,但我没有找到任何示例,我不清楚,我到底要实现什么?

I want to set the middle point of a colormap, i.e., my data goes from -5 to 10 and I want zero to be the middle point. I think the way to do it is by subclassing normalize and using the norm, but I didn't find any example and it is not clear to me, what exactly have I to implement?

推荐答案

请注意,在 matplotlib 3.2+ 版中 TwoSlopeNorm 类已添加.我认为它涵盖了您的用例.可以这样使用:

Note that in matplotlib version 3.2+ the TwoSlopeNorm class was added. I think it covers your use case. It can be used like this:

from matplotlib import colors
divnorm=colors.TwoSlopeNorm(vmin=-5., vcenter=0., vmax=10)
pcolormesh(your_data, cmap="coolwarm", norm=divnorm)

在 matplotlib 3.1 中,该类被称为 DivergingNorm.

In matplotlib 3.1 the class was called DivergingNorm.

这篇关于在 matplotlib 中定义颜色图的中点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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