title: Manually set legend colors using matplotlib Python
body: <p>I try to plot the following line plot, but I have difficulties to manually set legend colors. Currently the legend colors did not match the line colors. Any help would be very helpful. Thank you.</p>
  <pre><code>import random
  import matplotlib.pyplot as plt
  random.seed(10)
  
  data=[(i, i+random.randint(1,20), random.choice(list(&quot;ABC&quot;))) for i in range(2000,2025)]
  
  plt.figure(figsize=(14,8))
  for x, y,z in data:
      a=(x,x+y)
      b=(y+random.random(),y+random.random())
      if z==&quot;A&quot;:
          a=(x,x)
          plt.plot(a,b,&quot;bo&quot;,linestyle=&quot;-&quot;, linewidth=0.4, color=&quot;blue&quot;)
      elif z==&quot;B&quot;:
          plt.plot(a,b,&quot;bo&quot;,linestyle=&quot;-&quot;, linewidth=0.4, color=&quot;green&quot;)
      else:
          plt.plot(a,b,&quot;bo&quot;,linestyle=&quot;-&quot;, linewidth=0.4, color=&quot;red&quot;)
  ax = plt.gca()
  plt.legend(['A', 'B',&quot;C&quot;])
  </code></pre>