I am trying to color custom each bar of the chart below. I need to put specific colors that I can manually set each of the bars.
I already tried to use: #Attempt 1
colors = ['cyan', 'lightblue', 'lightgreen', 'tan','blue']
for patch, color in zip (bar_plot ['boxes'], colors):
patch.set_facecolor (color)
Result for Attempt 1-> What gives the error: 'AxesSubplot' object is not subscriptable
#Attempt 2
colors = ['#1b9e77', '#a9f971', '#fdaa48','#6890F0','#A890F0']
ax1 = dfPoputationResident.plot('Zona','Total_MSP', kind = 'bar', color = colors);
Result for Attempt 2-> That doesn't work, all bars are color '# 1b9e77', and not as spread, each bar assuming a color.
I believe this is happening because of my dataframe that is the result of a merge done earlier.
So before making the graph I reset the index.
dfPoputationResident = dfPoputationResident.reset_index () This is the dataframe after reset_index
Then I did:
ax1 = dfPoputationResident.plot ('Zone', 'Total_MSP', kind = 'bar');
But even after resetting the index, when I do
dfPoputationResident.columns
MultiIndex (levels = [['Total_MSP', 'Zone'], ['sum', '']],
codes = [[1,0], [1,0]])
With these characteristics in mind, how can I make the bar chart and place specific colors on each bar? Help me please. I'm new to Python.
Thank you!