I’m trying to switch the colors of my bar charts so that they’re consistent throughout. In the plots below, I want to make it so JP_Sales is orange in both charts and NA_Sales is blue in both charts.
The code for the first chart is:
JavaScript
x
4
1
Genre_sales.plot(kind= 'bar', rot=75, figsize = (15,10))
2
plt.suptitle('Sales by Region and Genre')
3
plt.ylabel('Total Units (Millions)')
4
The code for the second chart is:
JavaScript
1
5
1
PercentSales.plot(kind = 'bar', rot = 80, figsize=(15,10))
2
plt.suptitle('Percentage by Genre Sales by Region')
3
plt.xlabel('Genre')
4
plt.ylabel('Percent')
5
Advertisement
Answer
plot() has a color argument which takes a list in which you can specify the colors in the order in which the bars appear. So all you have to do is the following change for each plot:
JavaScript
1
6
1
#for Genre_sales if JP_sales is the first column and NA_sales is the second column:
2
Genre_sales.plot(kind = 'bar', rot = 75, color = ['orange', 'blue', 'green'], figsize = (15,10))
3
4
#for PercentSales if NA_sales is the first column and JP_sales is the second column:
5
PercentSales.plot(kind = 'bar', rot = 75, color = ['blue', 'orange', 'green', 'red'], figsize = (15,10))
6