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)