[英]How can I visualize a color mapping?
I have a function 我有一个功能 which takes a color in RGB format as input and outputs a color in RGB format. 它采用RGB格式的颜色作为输入并输出RGB格式的颜色。 It is guaranteed to be differentiable, but nothing else. 它保证是可区分的,但没有别的。 For simplicity, lets say it would just change the order of channels: 为简单起见,我们可以说它只会改变频道的顺序:
def f(r, g, b):
return b, g, r
Now I would like to visualize this by plotting two color bars like this: 现在我想通过绘制两个这样的颜色条来想象这个:
However, I have two problems with this: 但是,我有两个问题:
A different way of going about the colormaps than the rgb method is to use the matplotlib color maps, available here : 要去关于色彩映射表比RGB方式的另一种方法是使用matplotlib彩色地图,可在这里 :
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.