2017-04-23 51 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)