0

I am modelling my data on a bar graph using the following code

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), )

The legend does not match my column / row split so I am attempting to manually set it, but it is by default taking on the colour scheme assigned to the rows. I am aiming to show three approaches side by side , but the legend by default is taking the first 3 colour assignments. How to I manually set my legend colouring ? I presume it should be something like

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

but this obviously throws errors ?

Steve
  • 4,388
  • 3
  • 17
  • 25

0 Answers0