'Python bar graph only shows one color

I have this dataset (you can use this as a .csv/.txt file)

First name, Final,Grade
Aloysius,    49.0,   D-
University,  48.0,   D+
Gramma,      44.0,   C
Electric,    47.0,   B-
Fred,        45.0,   A-
Betty,       46.0,   C-
Cecil,       43.0,   F
Bif,         50.0,   B+
Andrew,      83.0,   A
Jim,         97.0,   A+
Art,         40.0,   D+
Jim,         45.0,   C+
Ima,         77.0,   B-
Benny,       90.0,   B-
Boy,          4.0,   B
Harvey,      40.0,   C

And I ran this:

import pandas as pd
import matplotlib.pyplot as plt

df['Grade'].value_counts().sort_values().plot(kind='barh', colormap='Reds')

This is the output: I specified the colormap='Reds' but it only shows one color
enter image description here

How can I make to this, a sequential red color:

enter image description here



Solution 1:[1]

You have to pick yourself your color for each grade:

import matplotlib.cm as cm

cmap = cm.get_cmap('Reds')
colors = cmap(np.linspace(0.1, 0.9, df['Grade'].nunique()))
ax = df['Grade'].value_counts('Grade', ascending=True).plot.barh(color=colors)
plt.show()

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Corralien