2017-04-23 52 views
1

我有一个功能enter image description here它采用RGB格式的颜色作为输入并输出RGB格式的颜色。它保证是可区分的,但没有别的。为简单起见,可以说,它只是改变通道的顺序:如何可视化颜色映射?

def f(r, g, b): 
    return b, g, r 

现在我想通过绘制两个颜色条,这样的想象是:

enter image description here

不过,我有两个这个问题:

  1. 我不知道该如何实现这个(所以:什么是用帆布交互合理的方式matplotlib?)
  2. 我不太确定这个色条是否合适。两个彼此相对的色轮可能会更好?两个颜色三角形彼此相邻?

回答

0

要去关于色彩映射表比RGB方式的另一种方法是使用matplotlib彩色地图,可here

import matplotlib.pyplot as plt 
from numpy import linspace 

sample_data = [1,5,10,20,45,50] ## y-values 

def clr_map(max_index): 
    cmap = plt.get_cmap('plasma') 
    ## limits of cmap are (0,1) 
    ## ==> use index within (0,1) for each color 
    clrs = [cmap(i) for i in linspace(0, 1, max_index)] 
    return clrs 

def clr_plot(data_list): 
    clrs = clr_map(len(data_list)) ## call function above 
    clr_list = [clr for clr in clrs] 
    x_loc = [val+1 for val in range(max(data_list))] ## x-values of barplot 
    ## use range for efficiency with multiple overlays 
    plt.bar(x_loc[0], data_list[0], label='bar 1', color=clr_list[0]) 
    plt.bar(x_loc[1], data_list[1], label='bar 2', color=clr_list[1]) 
    plt.bar(x_loc[2], data_list[2], label='bar 3', color=clr_list[2]) 
    plt.bar(x_loc[3], data_list[3], label='bar 4', color=clr_list[3]) 
    plt.bar(x_loc[4], data_list[4], label='bar 5', color=clr_list[4]) 
    plt.bar(x_loc[5], data_list[5], label='bar 6', color=clr_list[5]) 
    plt.legend(loc='best') 
    plt.show() 

clr_plot(sample_data)