title: How to change pyplot background colour in region of interest?
body: <p>I have a dataframe with a datetime index:</p>
  
  <pre><code>            A  B
  date            
  2020-05-04  0  0
  2020-05-05  5  0
  2020-05-07  2  0
  2020-05-09  2  0
  2020-05-18 -5  0
  2020-05-19 -1  0
  2020-05-20  0  0
  2020-05-21  1  0
  2020-05-22  0  0
  2020-05-23  3  0
  2020-05-24  1  1
  2020-05-25  0  1
  2020-05-26  4  1
  2020-05-27  3  1
  </code></pre>
  
  <p>I want to make a lineplot to track A over time and colour the background of the plot red when the values of B are 1. I have implemented this code to make the graph:</p>
  
  <pre><code>from matplotlib import dates as mdates
  from matplotlib.colors import ListedColormap
  import pandas as pd
  import numpy as np
  import matplotlib.pyplot as plt
  
  cmap = ListedColormap(['white','red'])
  
  ax.plot(data['A'])
  ax.set_xlabel('')
  plt.xticks(rotation = 30)
  ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
  ax.pcolorfast(ax.get_xlim(), ax.get_ylim(),
                data['B'].values[np.newaxis],
                cmap = cmap, alpha = 0.4)
  plt.axhline(y = 0, color = 'black')
  plt.tight_layout()
  </code></pre>
  
  <p>This gives me this graph:</p>
  
  <p><a href="https://i.stack.imgur.com/Lb5nf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Lb5nf.png" alt="enter image description here"></a></p>
  
  <p>But the red region incorrectly starts from 2020-05-21 rather than 2020-05-24 and it doesn't end at the end date in the dataframe. How can I alter my code to fix this?</p>