2016-07-01 8 views
2

私はimshow()を使って表示する範囲-70,0のデータを持っており、-70、-60の両方にpaternsがあるのでデータを表すために非線形のカラーバーを使用したいと思います範囲と-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) 

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

enter image description here

あなたはgammaを変更することができます。 ただし、この種の視覚化はお勧めできません。http://matplotlib.org/users/colormapnorms.html 「電力法」 - >「注」