title: How to position a rectangle to highlight categorical data?
body: <p>I want to draw rectangles along with the x-axis categorical values of the data. </p>
  
  <p>Some posts similar but not the one I look for.</p>
  
  <p><a href="https://stackoverflow.com/questions/37435369/matplotlib-how-to-draw-a-rectangle-on-image?rq=1">matplotlib: how to draw a rectangle on image</a></p>
  
  <p><a href="https://stackoverflow.com/questions/41892177/plotting-shapes-in-matplotlib-through-a-loop/41892694">Plotting shapes in Matplotlib through a loop</a></p>
  
  <p><a href="https://stackoverflow.com/questions/52518140/weird-behavior-of-matplotlib-plt-rectangle">Weird behavior of matplotlib plt.Rectangle</a></p>
  
  <p>These are the expected outputs;
  <a href="https://i.stack.imgur.com/hXdhN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/hXdhN.png" alt="enter image description here"></a></p>
  
  <p>I'd like to move the rectangle to each subsequent x-value. And save all images separately.</p>
  
  <p><a href="https://i.stack.imgur.com/sW78h.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sW78h.png" alt="enter image description here"></a></p>
  
  <p>The code for the plots above (with preliminary code for the rectangles):</p>
  
  <pre><code>import pandas as pd
  import numpy as np
  import seaborn as sns
  import matplotlib.pyplot as plt   
  
  data = pd.DataFrame(raw_data, columns = ['first_name', 'pre_score'])
  
  order = np.sort(data['first_name'].unique())
  
  save_images = r'D:\test'
  
  for x_names in order:
  
      print(x_names)
  
      sns.set_style("ticks")
      ax = sns.stripplot(x='first_name', y='pre_score', hue='first_name',order=order, jitter=True, dodge=False, size=6, zorder=0, alpha=0.5, linewidth =1, data=data)
      ax = sns.boxplot(x='first_name', y='pre_score', hue='first_name',order=order, dodge=False, showfliers=True, linewidth=0.8, showmeans=True, width=0.28, data=data)
      ax = sns.pointplot(x='first_name', y='pre_score', order=order, data=data, ci=None, color='black')
      fig_size = [18.0, 10.0]
      plt.rcParams["figure.figsize"] = fig_size
      ax.yaxis.set_tick_params(labelsize=14)
      ax.xaxis.set_tick_params(labelsize=14)
  
      plt.Rectangle((0, 0), 0.28, max(data['pre_score']), color="red");
  
      # ax.add_patch(plt.Rectangle(x_names, fill=False, linewidth=2.0))
  
      plt.savefig(save_images +x_names+'.png', dpi=150,bbox_inches="tight")
  </code></pre>
  
  <p>Got this after @JohanC
  <a href="https://i.stack.imgur.com/0jTgY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0jTgY.png" alt="enter image description here"></a></p>