From 489ee9e4b817b9409c301106da97beecf596066f Mon Sep 17 00:00:00 2001
From: = <francois.hamonic@gmail.com>
Date: Thu, 31 Mar 2022 17:41:58 +0200
Subject: [PATCH] whiskers plot

---
 plot_scripts/contraction_benefits_whiskers.py | 78 +++++++++++--------
 1 file changed, 44 insertions(+), 34 deletions(-)

diff --git a/plot_scripts/contraction_benefits_whiskers.py b/plot_scripts/contraction_benefits_whiskers.py
index aa1041f..4934cf9 100755
--- a/plot_scripts/contraction_benefits_whiskers.py
+++ b/plot_scripts/contraction_benefits_whiskers.py
@@ -1,53 +1,63 @@
 import matplotlib.pyplot as plt
 import csv
-import pylab
+
 
 def readCSV(file_name, delimiter=' '):
     file = csv.DictReader(open(file_name), delimiter=delimiter)
     return list([row for row in file])
 
+
 rows = readCSV('output/contraction_benefits.csv', ",")
 
-x_datas = range(0,105,5)
+x_datas = range(0, 105, 5)
+
 
 def get_datas(t, percent):
     return [100*(1-float(row["nb_{}_contract".format(t)])/float(row["nb_{}".format(t)])) for row in rows if int(row["percent_arcs"]) == percent]
 
-datas = [
-    # get_datas("constraints", p)
-    get_datas("vars", p)
-    # get_datas("elems", p)
-    for p in x_datas
-]
-
-fig_size = plt.rcParams["figure.figsize"]
-fig_size[0] = 10
-fig_size[1] = 5
-plt.rcParams["figure.figsize"] = fig_size
-
-plt.subplots_adjust(left=0.125, right=0.95, top=0.92, bottom=0.13)
-
-plt.rcParams.update({'font.size': 16})
-
-ymin = 0
-ymax = 100
-yrange = ymax - ymin
-
-y_border_percent = 7.5
-y_bottom = ymin - y_border_percent * yrange / 100
-y_top = ymax + y_border_percent * yrange / 100
-
-plt.ylim(y_bottom, y_top)
 
+vars_datas = [
+    get_datas("vars", p) for p in x_datas
+]
+constr_datas = [
+    get_datas("constraints", p) for p in x_datas
+]
+elems_datas = [
+    get_datas("elems", p) for p in x_datas
+]
 
-# plt.title("quebec-{}-{}-ECA value vs available budget.pdf".format(orig, median))
-plt.ylabel('percentage of elements\nremoved by the preprocessing', rotation=90, fontweight ='bold')
-plt.xlabel("percentage of restored arcs", fontweight ='bold')
+plt.rcParams["figure.figsize"] = (10, 8)
+plt.rcParams["font.size"] = 13.75
+
+fig, axs = plt.subplots(3)
+
+for i in [0, 1, 2]:
+    # axs[i].axhline(y=75, color='lightblue', linestyle='--')
+    # axs[i].axhline(y=50, color='dodgerblue', linestyle='--')
+    # axs[i].axhline(y=25, color='lightblue', linestyle='--')
+    axs[i].axhline(y=20, color='lightblue', linestyle='--')
+    axs[i].axhline(y=40, color='lightblue', linestyle='--')
+    axs[i].axhline(y=60, color='lightblue', linestyle='--')
+    axs[i].axhline(y=80, color='lightblue', linestyle='--')
+
+bplot1 = axs[0].boxplot(vars_datas, showfliers=False, patch_artist=True)
+axs[0].set(xlabel=None, ylabel='removed variables')
+axs[0].set_xticklabels([])
+bplot2 = axs[1].boxplot(constr_datas, showfliers=False, patch_artist=True)
+axs[1].set(xlabel=None, ylabel='removed constraints')
+axs[1].set_xticklabels([])
+bplot3 = axs[2].boxplot(elems_datas, showfliers=False, patch_artist=True)
+axs[2].set(xlabel="percentage of improvable arcs", ylabel='removed entries')
+axs[2].set_xticklabels([x if x % 10 == 0 else "" for x in x_datas])
+
+for bplot in (bplot1, bplot2, bplot3):
+    for patch in bplot['boxes']:
+        patch.set_facecolor('white')
 
-plt.boxplot(datas, showfliers=False)
-pylab.xticks(range(1, 1+len(datas)), x_datas)
-    
 # legend = plt.legend(loc='lower right', shadow=True, fontsize='medium')
 
+plt.tight_layout()
+fig.subplots_adjust(hspace=0.08)
+
+plt.savefig("output/contraction_benefits_whiskers.pdf", dpi=500)
 plt.show()
-plt.savefig("output/contraction_benefits_whiskers.pdf", dpi=500)
\ No newline at end of file
-- 
GitLab