-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot-varying_c.py
More file actions
132 lines (102 loc) · 4.33 KB
/
Copy pathplot-varying_c.py
File metadata and controls
132 lines (102 loc) · 4.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.ticker import FormatStrFormatter
import os
import seaborn as sns
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('sample', type=float)
parser.add_argument('n_itr', type=int)
args = parser.parse_args()
sample = args.sample
n_itr = args.n_itr
# Set ggplot style for the plots
plt.style.use('ggplot')
df_list = []
dataset_list = ['3A4', 'CB1', 'DPP4', 'HIVINT', 'HIVPROT', 'LOGD', 'METAB', 'NK1', 'OX1', 'OX2', 'PGP', 'PPB', 'RAT_F', 'TDI', 'THROMBIN']
for name in dataset_list:
df_ones = []
for j in range(1, 1+n_itr):
try:
df = pd.read_csv(os.path.join("result_varying_c", f"{sample:.2f}", f"{name} {sample:.2f}", f"{name} {sample:.2f} {j}.csv"))
except FileNotFoundError as e:
print(e)
df_ones.append(df)
df = pd.concat(df_ones).groupby("fdp_nominals", as_index=False).mean()
# if only to q=0.5
df = df[df['fdp_nominals'] <= 0.5]
df_list.append(df)
# Create a grid for subplots
fig, axs = plt.subplots(nrows=3, ncols=5, figsize=(18, 12))
axs = axs.flatten()
# Loop through datasets and plot the data on each subplot
for i, name in enumerate(dataset_list):
ax = axs[i]
if i == 0:
# Plot data for each model and conformal method
# print(df_list[i]['fdp_nominals'])
line1, = ax.plot(df_list[i]['fdp_nominals'], df_list[i]['fdps_bin_r'],
label='binarization + regression', marker='o', color='steelblue', alpha=0.8)
ax.legend(loc='best', bbox_to_anchor=(5.2, -2.9), frameon=True, shadow=False, ncol=4, fontsize=21)
else:
ax.plot(df_list[i]['fdp_nominals'], df_list[i]['fdps_bin_r'],
marker='o', color='steelblue', alpha=0.8)
# Reference line for y=x
ax.plot([0.05, 0.55], [0.05, 0.55], color='grey', alpha=0.7, linestyle='-.')
# Set axis labels
ax.set_title(f'{name}', fontsize=18)
ax.tick_params(axis='both', labelsize=11)
# Add grid lines
ax.grid(True)
for ax in axs:
for spine in ax.spines.values():
spine.set_visible(True)
spine.set_linewidth(1.2)
spine.set_edgecolor('gray')
# Adjust spacing between subplots
fig.subplots_adjust(wspace=0.2, hspace=0.3, top=0.9, bottom=0.13, left=0.07, right=0.96)
# Add global x and y labels, move them slightly outward
fig.text(0.5, 0.07, 'Nominal FDR', ha='center', fontsize=22) # Moved down slightly
fig.text(0.03, 0.5, 'Observed FDR', va='center', rotation='vertical', fontsize=22) # Moved left slightly
# Title for the entire plot
# fig.suptitle("FDP Control for all 15 Datasets", fontsize=16)
# Display the plot
plt.savefig(os.path.join("pic", "fdp_vc.pdf"))
# plt.show()
''''''''''''
# Create a grid for subplots
fig, axs = plt.subplots(nrows=3, ncols=5, figsize=(18, 12))
axs = axs.flatten()
# Loop through datasets and plot the data on each subplot
for i, name in enumerate(dataset_list):
ax = axs[i]
if i == 0:
# Plot data for each model and conformal method
line1, = ax.plot(df_list[i]['fdp_nominals'], df_list[i]['powers_bin_r'],
label='binarization + regression', marker='o', color='steelblue', alpha=0.8)
ax.legend(loc='best', bbox_to_anchor=(5.2, -2.9), frameon=True, shadow=False, ncol=4, fontsize=21)
else:
ax.plot(df_list[i]['fdp_nominals'], df_list[i]['powers_bin_r'],
marker='o', color='steelblue', alpha=0.8)
# Set axis labels
ax.set_title(f'{name}', fontsize=18)
ax.tick_params(axis='both', labelsize=11)
ax.yaxis.set_major_formatter(FormatStrFormatter('%.2f'))
# Add grid lines
ax.grid(True)
for ax in axs:
for spine in ax.spines.values():
spine.set_visible(True)
spine.set_linewidth(1.2)
spine.set_edgecolor('gray')
# Adjust spacing between subplots
fig.subplots_adjust(wspace=0.2, hspace=0.3, top=0.9, bottom=0.13, left=0.07, right=0.96)
# Add global x and y labels, move them slightly outward
fig.text(0.5, 0.07, 'Nominal FDR', ha='center', fontsize=22) # Moved down slightly
fig.text(0.03, 0.5, 'Observed Power', va='center', rotation='vertical', fontsize=22) # Moved left slightly
# Title for the entire plot
# fig.suptitle("Power for all 15 Datasets", fontsize=16)
# Display the plot
plt.savefig(os.path.join("pic", "power_vc.pdf"))
# plt.show()