Commit 489ee9e4 authored by Francois Hamonic's avatar Francois Hamonic
Browse files

whiskers plot

parent cae52ce0
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import csv import csv
import pylab
def readCSV(file_name, delimiter=' '): def readCSV(file_name, delimiter=' '):
file = csv.DictReader(open(file_name), delimiter=delimiter) file = csv.DictReader(open(file_name), delimiter=delimiter)
return list([row for row in file]) return list([row for row in file])
rows = readCSV('output/contraction_benefits.csv', ",") rows = readCSV('output/contraction_benefits.csv', ",")
x_datas = range(0,105,5) x_datas = range(0, 105, 5)
def get_datas(t, percent): 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] 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.rcParams["figure.figsize"] = (10, 8)
plt.ylabel('percentage of elements\nremoved by the preprocessing', rotation=90, fontweight ='bold') plt.rcParams["font.size"] = 13.75
plt.xlabel("percentage of restored arcs", fontweight ='bold')
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') # 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.show()
plt.savefig("output/contraction_benefits_whiskers.pdf", dpi=500)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment