Python: Barplot with colorbar
问题 I'm trying to make a bar plot with a color bar, each bar's hight is one variable (y) and each bar should have a color depending on another variable (c). What I've got to is this (simple example): data_x = [0,1,2,3] data_hight = [60,60,80,100] data_color = [1000,500,1000,900] data_color = [x / max(data_color) for x in data_color] fig, ax = plt.subplots(figsize=(15, 4)) my_cmap = plt.cm.get_cmap('GnBu') colors = my_cmap(data_color) rects = ax.bar(data_x, data_hight, color=colors) CS = plt