I'm trying to plot a bar graph in which certain bars need to be highlighted. How do I include a legend that explains what the colored bars are?
Below is my code. I want the legend to indicate that "Relevant bars" are blue (not gray, as it says at the moment).
import matplotlib.pyplot as plt
data = range(1,6)
labels = ['a','b','c','d','e']
relevant_bars = ['b','e']
bars = plt.bar(data, data, color='gray')
for i in range(len(bars)):
if labels[i] in relevant_bars:
bars[i].set_color('blue')
plt.xticks(pos, labels)
plt.legend(['Relevant bars']);