title: matplotlib how to fill_between step function
body: <p>I am trying to shade regions of a plot where an input signal is high (value = 1). The region should remain shaded until the signal goes low (value = 0). I have gotten pretty close, following a number of examples:
  <a href="http://matplotlib.org/examples/pylab_examples/axhspan_demo.html" rel="nofollow noreferrer">http://matplotlib.org/examples/pylab_examples/axhspan_demo.html</a>
  <a href="https://stackoverflow.com/questions/8270981/in-a-matplotlib-plot-can-i-highlight-specific-x-value-ranges">In a matplotlib plot, can I highlight specific x-value ranges?</a>
  <a href="https://stackoverflow.com/questions/8921296/how-do-i-plot-a-step-function-with-matplotlib-in-python">How do I plot a step function with Matplotlib in Python?</a></p>
  
  <p>The problem is that right now it is only shading directly under where the signal = 1, rather than to the <em>next</em> change to signal = 0 (step function). For example, in the image / code below, I would like the plot to be filled between 20-40 and 50-60 (rather than 20-30, and a spike under 40). How can I modify my code to achieve this? Thanks.
  <img src="https://i.stack.imgur.com/VQ9Rk.png" alt="output plot showing incorrect shading"></p>
  
  <pre><code>import numpy as np
  import matplotlib.pyplot as plt
  
  x = np.array([0,10,20,30,40,50,60])
  s = np.array([0,0,1,1,0,1,0])
  t = np.array([25,24,25,25,24,25,24])
  
  fig, ax = plt.subplots()
  
  ax.plot(x,t)
  ax.step(x,s,where='post')
  
  # xmin xmax ymin ymax
  plt.axis([0,60,0,30])
  
  ymin, ymax = plt.ylim()
  # want this to fill until the next "step"
  # i.e. should be filled between 20-40; 50-60
  ax.fill_between(x, ymin, ymax, where=s&gt;0, facecolor='green', alpha=0.5)
  
  plt.show()
  </code></pre>