title: multi colored plots in matplotlib plt based on certain properties of data
body: <p>I want to color the line in a plot based on the following of a data set on the y axis.</p>
  
  <pre><code>if data &gt; 0:
    color = 'r'
  if data = 0:
    color = 'g'
  if data &lt; 0:
    color = 'b'
  </code></pre>
  
  <p>Unfortunately I only know how to color the entire data set one color. I also couldn't find anything on the web. I'm assuming there is a way to do this without breaking up the dataset for every time the color changes.</p>
  
  <p>Below is an example of plotting the data with just one color.</p>
  
  <pre><code>import matplotlib.pyplot as plt
  import numpy as np
  
  # Simple data 
  x = np.linspace(0, 2 * np.pi, 400)
  data = np.sin(x ** 2)
  
  #plot
  f, ax = plt.subplots()
  ax.plot(x, data, color='r')
  
  plt.show()
  </code></pre>