【问题标题】:Arbitrary colorbar任意颜色条
【发布时间】:2017-12-17 05:06:32
【问题描述】:

我有使用 imshow() 显示的 -70,0 范围内的数据,并希望使用非线性颜色条来表示数据,因为我在 -70,-60 范围内都有模式,并且-70,0 范围。 我想要使​​用任意函数(参见示例)重新缩放/重新规范化颜色条的最简单方法,以便所有模式看起来都很好。

这是一个数据和函数的例子:

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)

【问题讨论】:

    标签: python matplotlib colorbar


    【解决方案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 在“幂律”->“注”下

    【讨论】:

      猜你喜欢
      • 2018-01-07
      • 1970-01-01
      • 2012-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-16
      相关资源
      最近更新 更多