MCPcopy Create free account
hub / github.com/cjrd/self-supervised-pretraining / gen_plots

Function gen_plots

utils/plot_augmentation_modified.py:34–83  ·  view source on GitHub ↗
(data, options)

Source from the content-addressed store, hash-verified

32
33#only deals with linear plots
34def gen_plots(data, options):
35
36 # linear plots
37 lin_dir = os.path.join(options['out_dir'], 'aug_robust_no_supervised')
38 os.makedirs(lin_dir, exist_ok=True)
39 linear_data = data[data.result_type=='linear-eval']
40 linear_data = linear_data[linear_data.variant=="linear-eval-lr"]
41 mpl.style.use('default')
42 #since catplot is a figure level function, it produces a new, separate plot which doesn't follow style of past graphs
43# with sns.axes_style("white"):
44 fig= sns.catplot(x='aug_type', y='result', hue='basetrain', data=linear_data, kind="point",s=10,
45 linestyle="-", legend_out=False,order=["Baseline","Remove\ngrayscale","Remove\ncolor","Crop + blur\nonly","Crop\nonly"])
46
47 #sets axis labels and title of graph
48 fig.set(xlabel='Augmentation Sets', ylabel='Change of Accuracy from Baseline', title=options['data_name'].replace("_", " ").title())
49 # fig._legend.set_title("Basetrain")
50 fig.ax.legend(title="Basetrain", fontsize="large", title_fontsize='large')
51 for ax in fig.axes.flat:
52 ax.set_title(options['data_name'].replace("_", " ").title(), fontsize=20)
53 ax.set_xlabel("Augmentation Sets", fontsize=18)
54
55 if 'chexpert' in options['data_name']:
56 ax.set_ylabel("AUROC Change", fontsize=18)
57 else:
58 ax.set_ylabel("Accuracy Change", fontsize=18)
59 xticks = ["Baseline","Remove\ngrayscale","Remove\ncolor","Crop+Blur\nonly","Crop\nonly"]
60 ax.set_xticklabels(xticks, rotation=0, fontsize=12)
61
62 yticks = [item.get_text() for item in ax.get_yticklabels()]
63 ax.set_yticklabels(yticks, rotation=0, fontsize=17)
64 # ax.tick_params(axis='y', labelsize='large')
65
66 ax.spines['bottom'].set_color('1')
67 ax.spines['top'].set_color('1')
68 ax.spines['right'].set_color('1')
69 ax.spines['left'].set_color('1')
70 ax.patch.set_facecolor('0.97')
71 ax.grid(axis='y', color='grey', dashes=[10, 4])
72
73# print(ax.spines)
74
75# ax.legend(fontsize=8)
76 #gets rid of other graph created
77 plt.close(1)
78
79 #creates output file
80 outplot = os.path.join(lin_dir, '{}_{}.pdf'.format(options['data_name']+ "_augmentation", "no_supervised"))
81
82 #saves Figure 1, but Figure 1 is the empty graph created (NOT SNS Graph)
83 fig.savefig(outplot, format='pdf', bbox_inches='tight')
84
85def set_size(width, fraction=1):
86 """ Set figure dimensions to avoid scaling in LaTeX.

Callers 1

mainFunction · 0.70

Calls 2

setMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected