1

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.

current plot

second plot

The code for the first chart is:

Genre_sales.plot(kind= 'bar', rot=75, figsize = (15,10))
plt.suptitle('Sales by Region and Genre')
plt.ylabel('Total Units (Millions)')

The code for the second chart is:

PercentSales.plot(kind = 'bar', rot = 80, figsize=(15,10))
plt.suptitle('Percentage by Genre Sales by Region')
plt.xlabel('Genre')
plt.ylabel('Percent')
JohanC
  • 71,591
  • 8
  • 33
  • 66
CLook
  • 57
  • 4
  • 1
    You need the **second** answer from [https://stackoverflow.com/questions/25689558/pandas-bar-plot-specify-bar-color-by-column/63280537#63280537](Pandas bar plot, specify bar color by column), so using a dictionary mapping the names to their color. – JohanC Mar 08 '21 at 02:45

2 Answers2

3

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:

#for Genre_sales if JP_sales is the first column and NA_sales is the second column:
Genre_sales.plot(kind = 'bar', rot = 75, color = ['orange', 'blue', 'green'], figsize = (15,10))

#for PercentSales if NA_sales is the first column and JP_sales is the second column:
PercentSales.plot(kind = 'bar', rot = 75, color = ['blue', 'orange', 'green', 'red'], figsize = (15,10))
pakpe
  • 5,391
  • 2
  • 8
  • 23
0

You use the 'set_color()' function

So in your case, if you wanted to set it to red you will do the following:

Genre_sales.set_color('r')
plt.show()

Similarly:

PercentSales.set_color('b')
plt.show()
amichow
  • 45
  • 9