title: Why isn't the legend in matplotlib correctly displaying the colors?
body: <p>I have a plot where I am displaying 3 different lineplots. I am thus specifying the legend explicitly to display 3 colors, one for each of the plots. Below is a toy example:</p>
  
  <pre><code>import matplotlib.pyplot as plt
  
  for i in range(1,20):
      if i%3==0 and i%9!=0:
          plt.plot(range(1,20),[i+3 for i in range(1,20)], c='b')
      elif i%9==0:
          plt.plot(range(1,20),[i+9 for i in range(1,20)], c='r')
      else:
          plt.plot(range(1,20),range(1,20), c='g')
  plt.legend(['Multiples of 3 only', 'Multiples of 9', 'All the rest'])
  plt.show()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/h3OUj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/h3OUj.png" alt="enter image description here"></a></p>
  
  <p>But the legend does not display the colors correctly. Why is that and how to fix it?</p>