Spaces:
Sleeping
Sleeping
Update src/vis_utils.py
Browse files- src/vis_utils.py +48 -4
src/vis_utils.py
CHANGED
@@ -45,11 +45,11 @@ def benchmark_plot(benchmark_type, methods_selected, x_metric, y_metric):
|
|
45 |
title = f"{x_metric} vs {y_metric}"
|
46 |
return draw_scatter_plot_similarity(methods_selected, x_metric, y_metric, title)
|
47 |
elif benchmark_type == 'function':
|
48 |
-
plot_function_results("./data/function_results.csv", x_metric, y_metric, methods_selected)
|
49 |
elif benchmark_type == 'family':
|
50 |
-
plot_family_results("./data/family_results.csv", methods_selected, x_metric, save_path="./plot_images")
|
51 |
-
|
52 |
-
return "
|
53 |
|
54 |
def general_visualizer(methods_selected, x_metric, y_metric):
|
55 |
df = pd.read_csv(CSV_RESULT_PATH)
|
@@ -200,4 +200,48 @@ def plot_family_results(file_path, method_names, metric, save_path="./plot_image
|
|
200 |
ax.get_figure().savefig(filename, dpi=400, bbox_inches='tight')
|
201 |
plt.close() # Close the plot to free memory
|
202 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
203 |
return filename
|
|
|
45 |
title = f"{x_metric} vs {y_metric}"
|
46 |
return draw_scatter_plot_similarity(methods_selected, x_metric, y_metric, title)
|
47 |
elif benchmark_type == 'function':
|
48 |
+
return plot_function_results("./data/function_results.csv", x_metric, y_metric, methods_selected)
|
49 |
elif benchmark_type == 'family':
|
50 |
+
return plot_family_results("./data/family_results.csv", methods_selected, x_metric, save_path="./plot_images")
|
51 |
+
elif benchmark_type == "affinity":
|
52 |
+
return plot_affinity_results("./data/affinity_results.csv", methods_selected, x_metric, save_path="./plot_images")
|
53 |
|
54 |
def general_visualizer(methods_selected, x_metric, y_metric):
|
55 |
df = pd.read_csv(CSV_RESULT_PATH)
|
|
|
200 |
ax.get_figure().savefig(filename, dpi=400, bbox_inches='tight')
|
201 |
plt.close() # Close the plot to free memory
|
202 |
|
203 |
+
return filename
|
204 |
+
|
205 |
+
def plot_affinity_results(file_path, method_names, metric, save_path="./plot_images"):
|
206 |
+
# Load the CSV data
|
207 |
+
df = pd.read_csv(file_path)
|
208 |
+
|
209 |
+
# Filter for selected methods
|
210 |
+
df = df[df['Method'].isin(method_names)]
|
211 |
+
|
212 |
+
# Gather columns related to the specified metric and validate
|
213 |
+
metric_columns = [col for col in df.columns if col.startswith(f"{metric}_")]
|
214 |
+
if not metric_columns:
|
215 |
+
print(f"No columns found for metric '{metric}'.")
|
216 |
+
return None
|
217 |
+
|
218 |
+
# Reshape data for plotting
|
219 |
+
df_long = pd.melt(df[['Method'] + metric_columns], id_vars=['Method'], var_name='Fold', value_name='Value')
|
220 |
+
df_long['Fold'] = df_long['Fold'].apply(lambda x: int(x.split('_')[-1])) # Extract fold index for sorting
|
221 |
+
|
222 |
+
# Set up the plot
|
223 |
+
sns.set(rc={'figure.figsize': (13.7, 8.27)})
|
224 |
+
sns.set_theme(style="whitegrid", color_codes=True)
|
225 |
+
|
226 |
+
# Create a boxplot for the metric
|
227 |
+
ax = sns.boxplot(data=df_long, x='Value', y='Method', hue='Fold', whis=np.inf, orient="h")
|
228 |
+
|
229 |
+
# Customize x-axis and y-axis tickers and grid
|
230 |
+
ax.xaxis.set_major_locator(ticker.MultipleLocator(5))
|
231 |
+
ax.get_xaxis().set_minor_locator(mpl.ticker.AutoMinorLocator())
|
232 |
+
ax.get_yaxis().set_minor_locator(mpl.ticker.AutoMinorLocator())
|
233 |
+
ax.grid(b=True, which='major', color='gainsboro', linewidth=1.0)
|
234 |
+
ax.grid(b=True, which='minor', color='whitesmoke', linewidth=0.5)
|
235 |
+
|
236 |
+
# Apply custom color settings to y-axis labels
|
237 |
+
set_colors_and_marks_for_representation_groups(ax)
|
238 |
+
|
239 |
+
# Ensure save path exists
|
240 |
+
os.makedirs(save_path, exist_ok=True)
|
241 |
+
|
242 |
+
# Save the plot
|
243 |
+
filename = os.path.join(save_path, f"{metric}_affinity_results.png")
|
244 |
+
ax.get_figure().savefig(filename, dpi=400, bbox_inches='tight')
|
245 |
+
plt.close() # Close the plot to free memory
|
246 |
+
|
247 |
return filename
|