我想用某种颜色来匹配积木。已经有tried my_colors method
和set_color_cycle
,但是颜色仍然是从列表中随机选择的。
my_colors
my_colors = {'#FF0000', '#FFDEAD', '#FFFF00', '#00BFFF', '#4169E1', '#66CDAA', '#006400', '#7B68EE'}
ax = pd.DataFrame(compare_percent).T.plot.bar(stacked=True, figsize=(5,50), title='Size %', color=my_colors antialiased=True)
for p in ax.patches:
ax.annotate(str(p.get_height()*100)[:5] + '%', (p.get_x() * 0.2, p.get_y() * 1.02), color='white', size=14)
set_color_cycle
ax = pd.DataFrame(compare_percent).T.plot.bar(stacked=True, figsize=(5,50), title='Size %', antialiased=True)
ax.set_color_cycle(['#FF0000', '#FFDEAD', '#FFFF00', '#00BFFF', '#4169E1', '#66CDAA', '#006400', '#7B68EE'])
for p in ax.patches:
ax.annotate(str(p.get_height()*100)[:5] + '%', (p.get_x() * 0.2, p.get_y() * 1.02), color='white', size=14)
关于如何在绘图上强制颜色顺序的任何建议?