mgyigit commited on
Commit
04421b9
·
verified ·
1 Parent(s): 4c3d005

Update src/vis_utils.py

Browse files
Files changed (1) hide show
  1. src/vis_utils.py +22 -11
src/vis_utils.py CHANGED
@@ -230,32 +230,43 @@ def plot_affinity_results(method_names, metric, affinity_path="/tmp/affinity_res
230
 
231
  # Gather columns related to the specified metric and validate
232
  metric_columns = [col for col in df.columns if col.startswith(f"{metric}_")]
233
-
234
- # Reshape data for plotting
235
- df_long = pd.melt(df[['Method'] + metric_columns], id_vars=['Method'], var_name='Fold', value_name='Value')
236
- df_long['Fold'] = df_long['Fold'].apply(lambda x: int(x.split('_')[-1])) # Extract fold index for sorting
237
 
238
  df = df.fillna(0)
239
 
 
 
 
240
  # Set up the plot
241
- sns.set(rc={'figure.figsize': (13.7, 8.27)})
242
  sns.set_theme(style="whitegrid", color_codes=True)
243
 
244
- # Create a boxplot for the metric
245
- ax = sns.boxplot(data=df_long, x='Value', y='Method', hue='Fold', whis=np.inf, orient="h")
246
-
247
- # Customize x-axis and y-axis tickers and grid
 
 
 
 
248
  ax.xaxis.set_major_locator(ticker.MultipleLocator(5))
249
- ax.get_xaxis().set_minor_locator(ticker.AutoMinorLocator())
250
- ax.get_yaxis().set_minor_locator(ticker.AutoMinorLocator())
251
  ax.grid(visible=True, which='major', color='gainsboro', linewidth=1.0)
252
  ax.grid(visible=True, which='minor', color='whitesmoke', linewidth=0.5)
253
 
 
 
 
 
 
254
  # Apply custom color settings to y-axis labels
255
  for label in ax.get_yticklabels():
256
  method = label.get_text()
257
  label.set_color(get_method_color(method))
258
 
 
 
 
259
  # Save the plot
260
  save_path = "/tmp"
261
  filename = os.path.join(save_path, f"{metric}_affinity_results.png")
 
230
 
231
  # Gather columns related to the specified metric and validate
232
  metric_columns = [col for col in df.columns if col.startswith(f"{metric}_")]
 
 
 
 
233
 
234
  df = df.fillna(0)
235
 
236
+ df = df.T
237
+
238
+ print(df)
239
  # Set up the plot
240
+ sns.set(rc={'figure.figsize': (11.7, 8.27)})
241
  sns.set_theme(style="whitegrid", color_codes=True)
242
 
243
+ # Create the boxplot
244
+ ax = sns.boxplot(data=df_corr, whis=np.inf, orient="h")
245
+
246
+ # Add a swarmplot on top of the boxplot
247
+ sns.swarmplot(data=df_corr, orient="h", color=".1", ax=ax)
248
+
249
+ # Set labels and x-axis formatting
250
+ ax.set_xlabel("Percent Pearson Correlation")
251
  ax.xaxis.set_major_locator(ticker.MultipleLocator(5))
252
+ ax.xaxis.set_minor_locator(ticker.AutoMinorLocator())
253
+ ax.yaxis.set_minor_locator(ticker.AutoMinorLocator())
254
  ax.grid(visible=True, which='major', color='gainsboro', linewidth=1.0)
255
  ax.grid(visible=True, which='minor', color='whitesmoke', linewidth=0.5)
256
 
257
+ # Add reference lines
258
+ ax.plot((best_pipr, best_pipr), (-1, len(df_corr.columns) + 1), color='black', label='Best PIPR')
259
+ ax.plot((baseline_ac, baseline_ac), (-1, len(df_corr.columns) + 1), color='purple', linestyle='dashed', label='Baseline AC')
260
+ ax.plot((baseline_ctd, baseline_ctd), (-1, len(df_corr.columns) + 1), color='brown', linestyle='dashed', label='Baseline CTD')
261
+
262
  # Apply custom color settings to y-axis labels
263
  for label in ax.get_yticklabels():
264
  method = label.get_text()
265
  label.set_color(get_method_color(method))
266
 
267
+ # Add legend
268
+ ax.legend(loc='best', frameon=True)
269
+
270
  # Save the plot
271
  save_path = "/tmp"
272
  filename = os.path.join(save_path, f"{metric}_affinity_results.png")