2016-07-01 2 views
2

У меня есть данные, которые находятся в диапазоне -70,0, которые я показываю с помощью imshow(), и хотели бы использовать нелинейную цветную панель для представления данных, поскольку у меня есть paterns как в -70, -60 диапазон и -70,0. Я хотел бы, чтобы самый простой способ перемасштабировать/перенормировать с помощью произвольной функции (см. Пример) цветной панели, чтобы все патерны выглядели красиво.Arbitrary colorbar

Ниже приведен пример данных и функции:

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 в разделе «Энергетическое право» -> «Примечание»