0

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

enter image description here

This code was run using Python 3.6 :

StackUser
  • 142
  • 8
  • 1
    Please do not post a picture of your dataset. Check out [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) – Diziet Asahi Feb 05 '18 at 20:39
  • See [Why is the order in dictionaries and sets arbitrary?](https://stackoverflow.com/questions/15479928/why-is-the-order-in-dictionaries-and-sets-arbitrary/). – ImportanceOfBeingErnest Feb 05 '18 at 21:23

0 Answers0