任意颜色条 [英] Arbitrary colorbar

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

问题描述

我有使用imshow()显示的-70,0范围内的数据,并且由于我在-70,-60范围和-70,0范围.我想使用颜色函数的任意函数(参见示例)来重新缩放/重新规格化的最简单方法,以便所有样式都能很好地显示.

I have data that is in the range -70,0 that I display using imshow() and would like to use a non-linear colorbar to represent the data as I have paterns both in the -70,-60 range and -70,0 range. I would like the easiest way to rescale/renormalize using an arbitrary function (see example) the colorbar so that all paterns appear nicely.

以下是数据和功能的示例:

Here is an example of data and function:

sample_data=(np.ones((20,20))*np.linspace(0,1,20)**3)*70-70

def renorm(value):
    """
    Example of the way I would like to adjust the colorbar but it might as well be an arbitrary function
    Returns a number between 0 and 1 that would correspond to the color wanted on the original colorbar
    For the cmap 'inferno' 0 would be the dark purple, 0.5 the purplish orange and 1 the light yellow
    """

    return np.log(value+70+1)/np.log(70+1)

推荐答案

这是我设法做到的:

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import PowerNorm
sample_data=(np.ones((20,20))*np.linspace(0,1,20)**3)*70-70
plt.figure()
im = plt.imshow(sample_data+70, norm=PowerNorm(gamma=0.5))
cbar = plt.colorbar(orientation='horizontal')
cbar.ax.set_xticklabels(np.arange(-70, 0, 8))
plt.show()

您可以更改 gamma .但是,不建议使用这种可视化方法,请参见: http://matplotlib.org/users/colormapnorms.html 在电源法"下->注释"

You can change the gamma. However, this kind of visualization is not recommended, see: http://matplotlib.org/users/colormapnorms.html under "Power-law" -> "Note"

这篇关于任意颜色条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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