I am trying to change this plot
to match this style
Changes required are as follows:
- change colour of individual boxes for oxide to red, transition to green and fresh to blue
- add legend for oxide, transition and fresh
- Simplify x-axis to include only the elements
Here is an excerpt of my data:
Oxidation Elements GAI
1.OXIDE Ag_ppm 1
2.TRANS Ag_ppm 1
2.TRANS Ag_ppm 0
2.TRANS Ag_ppm 2
2.TRANS Ag_ppm 2
2.TRANS Ag_ppm 1
3.FRESH Ag_ppm 2
3.FRESH Ag_ppm 0
3.FRESH Ag_ppm 0
3.FRESH Ag_ppm 1
3.FRESH Ag_ppm 0
3.FRESH Ag_ppm 0
1.OXIDE Ag_ppm 0
1.OXIDE Ag_ppm 1
1.OXIDE Ag_ppm 0
1.OXIDE Ag_ppm 0
1.OXIDE Ag_ppm 0
1.OXIDE Ag_ppm 0
1.OXIDE Cu_ppm 1
2.TRANS Cu_ppm 1
2.TRANS Cu_ppm 1
2.TRANS Cu_ppm 1
2.TRANS Cu_ppm 2
2.TRANS Cu_ppm 1
3.FRESH Cu_ppm 2
3.FRESH Cu_ppm 1
3.FRESH Cu_ppm 2
3.FRESH Cu_ppm 2
3.FRESH Cu_ppm 2
3.FRESH Cu_ppm 1
3.FRESH Cu_ppm 2
1.OXIDE Cu_ppm 3
1.OXIDE Cu_ppm 3
1.OXIDE Cu_ppm 3
1.OXIDE Cu_ppm 4
1.OXIDE Cu_ppm 2
1.OXIDE Mg_pct 1
1.OXIDE Mg_pct 1
1.OXIDE Mg_pct 3
1.OXIDE Mg_pct 2
1.OXIDE Mg_pct 1
1.OXIDE Mg_pct 1
1.OXIDE Mg_pct 2
1.OXIDE Mg_pct 2
2.TRANS Mg_pct 2
2.TRANS Mg_pct 2
2.TRANS Mg_pct 2
2.TRANS Mg_pct 2
2.TRANS Mg_pct 2
3.FRESH Mg_pct 2
3.FRESH Mg_pct 2
3.FRESH Mg_pct 2
3.FRESH Mg_pct 2
3.FRESH Mg_pct 2
Here is my current script:
# Plot boxplots
fig, ax = plt.subplots(figsize = (20,8))
# Box plot properties
mean = dict(marker = 'x', mec = 'Black', ms = 9)
median=dict(color ="Black", lw=1.2)
whisker=dict(color ="Black", lw=1.2)
cap=dict(color ="Black", lw=1.2)
flier=dict(markerfacecolor= 'green', ms=10)
key_label = ['Ag','Cu','Mg']
key_ox = ['Oxide','Transition','Fresh','Oxide','Transition','Fresh','Oxide','Transition','Fresh']
col_ox = ['r','g','b','r','g','b','r','g','b']
gai_waste.boxplot(ax=ax, by = ['Elements', 'Oxidation'], column =["GAI"],
color = '#ADD8E6', patch_artist=True, whis=[10, 90], #widths=0.2,
whiskerprops = whisker, showmeans=True, meanprops = mean, medianprops=median, capprops = cap, showfliers=False,
grid = True, rot = 90, fontsize = 'medium')
plt.ylabel("GAI", fontsize = 'x-large', fontname='Calibri', weight='bold')
plt.xlabel(None)
plt.yticks(fontsize = 'large', fontname='Calibri')
plt.xticks(np.arange(1, 10, 1),labels=key_ox,ha='center',fontsize = 'large', fontname='Calibri', rotation = 0)
ax.yaxis.set_major_formatter(FormatStrFormatter('%.0f'))
plt.grid(True, which='both', color='lightgrey',ls = '--')
plt.suptitle('')
plt.title('')
x=2
for i in range(3):
plt.text(x = x , y = -5.5, s = str(key_label[i]),horizontalalignment='center', fontsize = 'x-large', weight='bold')
x+=3
Thanks in advance for your help!