I want to draw rectangles along with the x-axis categorical values of the data.
Some posts similar but not the one I look for.
matplotlib: how to draw a rectangle on image
Plotting shapes in Matplotlib through a loop
Weird behavior of matplotlib plt.Rectangle
These are the expected outputs;
I'd like to move the rectangle to each subsequent x-value. And save all images separately.
The code for the plots above (with preliminary code for the rectangles):
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")