title: How to label colored bars on matplotlib?
body: <p>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?</p>
  <p>Below is my code. I want the legend to indicate that &quot;Relevant bars&quot; are blue (not gray, as it says at the moment).</p>
  <pre><code>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']);
  </code></pre>
  <p><a href="https://i.stack.imgur.com/8HvvP.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8HvvP.png" alt="enter image description here" /></a></p>