Silviu Tofan Silviu Tofan - 1 month ago 12
Python Question

Different box plots on the same oX position

I am trying to combine box plots with a scatter plot for an algorithm scoring visualization. My data is divided as following:


  • oX - information about the time period (1 year, 2 years, etc.)

  • oY - information about the score

  • 2 algorithms for each period with different simulation results (plotted as boxplots)

  • 2 heuristics with a single value (plotted as a point)



I'm trying to easily compare method efficiency for each period of time.

Small sample data:

1 year 2 years
A1 A2 H1 H2 A1 A2 H1 H2
124 168 155 167 130 130 150 164
102 155 100 172
103 153 117 145
102 132 145 143
145 170 133 179
136 125 115 153
116 150 136 131
146 192 106 148
124 122 127 158
128 123 149 200
141 158 137 156


I'm trying to get something that looks like this:
enter image description here

So far I've cleared up my data to have the observations for each algorithm (RS, EA) and for each period (52, 104, 156 etc.) separately like so but I can't figure out how to group them per period while drawing 2 different boxplots for the same X tick. I assume once I'd sort out the boxplot dataframe and plot, I can just plot the scatter on top.

Answer

Managed to solve this meanwhile, in case it helps anyone else out:

ax1 = sns.boxplot(data = meta, x = 'Time', y = 'PRS', color = '#880BDD', linewidth=0.8)
ax1 = sns.boxplot(data = meta, x = 'Time', y = 'EA', color = '#0BC9DD', linewidth=0.8)
ax1 = sns.boxplot(data = meta, x = 'Time', y = 'ERS', color = '#9BD19D', linewidth=0.8)
ax1 = sns.pointplot(data = simple, x = 'Time', y = 'Greedy Average', color='#FFC48C', markers ='s', join=False)
ax1 = sns.pointplot(data = simple, x = 'Time', y = 'Greedy Total', color='#FF9F80', markers='o', join=False)
ax1 = sns.pointplot(data = simple, x = 'Time', y = 'Greedy Weeks', color='#F56991', markers='*', join=False)
ax1.set(xlabel = "Planning Horizon (weeks)")
ax1.set(ylabel = "Hypervolume")
EA = mpatches.Patch(color='#0BC9DD', label = 'EA')
PRS = mpatches.Patch(color='#880BDD', label = 'PRS')
ERS = mpatches.Patch(color='#9BD19D', label = 'ERS')
GA = mlines.Line2D([], [], color='#FFC48C', marker = 's', label = 'Greedy Average')
GT = mlines.Line2D([], [],color='#FF9F80', label = 'Greedy Total', marker = 'o')
GW = mlines.Line2D([], [],color='#F56991', label = 'Greedy Weeks', marker = '*')
plt.legend(handles = [EA, ERS, PRS, GA, GT, GW], loc = 'bottom left', title = "Algorithm")
ax1.set_title("Algorithm Comparison")

Results in this:

enter image description here