更改我的传奇plt plot python上的颜色

时间:2017-11-09 11:16:05

标签: pandas matplotlib graph

我使用以下代码在条形图上建模我的数据

colours = ["r", "r","r","r","r","g","g","g","g","g","b","b","b","b","b",]

AAA = [ i for i in range(15)]
BBB = [ i for i in range(15)]
CCC = [ i for i in range(15)]

df = pd.DataFrame({"AAA" : AAA, "BBB" : BBB , "CCC" : CCC})

df = df.T
df.plot(kind = 'bar', color = colours)
plt.xticks(rotation = 'horizontal')
plt.legend(["AAA", "BBB", "BBB"]);
plt.show()
plt.legend(loc='center left', bbox_to_anchor=(1.0, 0.5), )

图例与我的列/行拆分不匹配,因此我尝试手动设置它,但默认情况下它采用分配给行的颜色方案。我的目标是并排显示三种方法,但默认情况下,图例采用前3种颜色分配。如何手动设置我的图例着色?我认为它应该像

plt.legend(["AAA", "BBB", "CCC"], color = ['r', 'g', 'b']);

但这显然会引发错误?

0 个答案:

没有答案