I have the following Python code. I am unable to get the color of the bars in the chart to match the color name on the x axis. I want "red" to have red color bars and "white" to have blue color bar graphs. But the output seems to generate a random mix of both.
import pandas as pd
import matplotlib.pyplot as plt
colors={'red','blue'}
counts = df.groupby(['quality', 'color']).count()
counts.plot(kind='bar', title="Counts by Wine Quality and Color", color=colors, alpha=.7)
print(counts)
plt.ylabel('Count', fontsize=18)
plt.xlabel('Quality and Color', fontsize=18)
plt.show()
Here is data set as text:
quality color
3 red 10
white 20
4 red 53
white 163
5 red 681
white 1457
6 red 638
white 2198
7 red 199
white 880
8 red 18
white 175
9 white 5
This code was run using Python 3.6 :