Spaces:
Running
Running
Update src/vis_utils.py
Browse files- src/vis_utils.py +55 -6
src/vis_utils.py
CHANGED
|
@@ -44,10 +44,10 @@ def benchmark_plot(benchmark_type, methods_selected, x_metric, y_metric):
|
|
| 44 |
elif benchmark_type == 'similarity':
|
| 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 == '
|
| 48 |
-
|
| 49 |
-
elif benchmark_type == '
|
| 50 |
-
|
| 51 |
else:
|
| 52 |
return "Invalid benchmark type selected."
|
| 53 |
|
|
@@ -78,7 +78,7 @@ def general_visualizer(methods_selected, x_metric, y_metric):
|
|
| 78 |
|
| 79 |
return plot_path
|
| 80 |
|
| 81 |
-
def
|
| 82 |
df = pd.read_csv(CSV_RESULT_PATH)
|
| 83 |
# Filter the dataframe based on selected methods
|
| 84 |
filtered_df = df[df['method_name'].isin(methods_selected)]
|
|
@@ -122,7 +122,7 @@ def draw_scatter_plot_similarity(methods_selected, x_metric, y_metric, title):
|
|
| 122 |
|
| 123 |
return filename
|
| 124 |
|
| 125 |
-
def
|
| 126 |
# Load data
|
| 127 |
df = pd.read_csv(file_path)
|
| 128 |
|
|
@@ -146,9 +146,58 @@ def visualize_aspect_metric_clustermap(file_path, aspect, metric, method_names):
|
|
| 146 |
set_colors_and_marks_for_representation_groups(ax)
|
| 147 |
|
| 148 |
# Save the plot as an image
|
|
|
|
| 149 |
os.makedirs(save_path, exist_ok=True) # Create directory if it doesn't exist
|
| 150 |
filename = os.path.join(save_path, f"{aspect}_{metric}_heatmap.png")
|
| 151 |
plt.savefig(filename, dpi=400, bbox_inches='tight')
|
| 152 |
plt.close() # Close the plot to free memory
|
| 153 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 154 |
return filename
|
|
|
|
| 44 |
elif benchmark_type == 'similarity':
|
| 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 |
else:
|
| 52 |
return "Invalid benchmark type selected."
|
| 53 |
|
|
|
|
| 78 |
|
| 79 |
return plot_path
|
| 80 |
|
| 81 |
+
def plot_similarity_results(methods_selected, x_metric, y_metric, title):
|
| 82 |
df = pd.read_csv(CSV_RESULT_PATH)
|
| 83 |
# Filter the dataframe based on selected methods
|
| 84 |
filtered_df = df[df['method_name'].isin(methods_selected)]
|
|
|
|
| 122 |
|
| 123 |
return filename
|
| 124 |
|
| 125 |
+
def plot_function_results(file_path, aspect, metric, method_names):
|
| 126 |
# Load data
|
| 127 |
df = pd.read_csv(file_path)
|
| 128 |
|
|
|
|
| 146 |
set_colors_and_marks_for_representation_groups(ax)
|
| 147 |
|
| 148 |
# Save the plot as an image
|
| 149 |
+
save_path = "./plot_images" # Ensure this folder exists or adjust the path
|
| 150 |
os.makedirs(save_path, exist_ok=True) # Create directory if it doesn't exist
|
| 151 |
filename = os.path.join(save_path, f"{aspect}_{metric}_heatmap.png")
|
| 152 |
plt.savefig(filename, dpi=400, bbox_inches='tight')
|
| 153 |
plt.close() # Close the plot to free memory
|
| 154 |
|
| 155 |
+
return filename
|
| 156 |
+
|
| 157 |
+
def plot_family_results(file_path, method_names, metric, save_path="./plot_images"):
|
| 158 |
+
# Load data
|
| 159 |
+
df = pd.read_csv(file_path)
|
| 160 |
+
|
| 161 |
+
# Filter by method names and selected metric columns
|
| 162 |
+
df = df[df['Method'].isin(method_names)]
|
| 163 |
+
metric_columns = [col for col in df.columns if col.startswith(f"{metric}_")]
|
| 164 |
+
|
| 165 |
+
# Check if there are columns matching the selected metric
|
| 166 |
+
if not metric_columns:
|
| 167 |
+
print(f"No columns found for metric '{metric}'.")
|
| 168 |
+
return None
|
| 169 |
+
|
| 170 |
+
# Reshape data for plotting
|
| 171 |
+
df_long = pd.melt(df[['Method'] + metric_columns], id_vars=['Method'], var_name='Fold', value_name='Value')
|
| 172 |
+
df_long['Fold'] = df_long['Fold'].apply(lambda x: int(x.split('_')[-1])) # Extract fold index
|
| 173 |
+
|
| 174 |
+
# Set up the plot
|
| 175 |
+
sns.set(rc={'figure.figsize': (13.7, 18.27)})
|
| 176 |
+
sns.set_theme(style="whitegrid", color_codes=True)
|
| 177 |
+
ax = sns.boxplot(data=df_long, x='Value', y='Method', hue='Fold', whis=np.inf, orient="h")
|
| 178 |
+
|
| 179 |
+
# Customize x-axis and y-axis tickers and grid
|
| 180 |
+
ax.xaxis.set_major_locator(ticker.MultipleLocator(0.2))
|
| 181 |
+
ax.get_xaxis().set_minor_locator(ticker.AutoMinorLocator())
|
| 182 |
+
ax.get_yaxis().set_minor_locator(ticker.AutoMinorLocator())
|
| 183 |
+
ax.grid(b=True, which='major', color='gainsboro', linewidth=1.0)
|
| 184 |
+
ax.grid(b=True, which='minor', color='whitesmoke', linewidth=0.5)
|
| 185 |
+
ax.set_xlim(0, 1)
|
| 186 |
+
|
| 187 |
+
# Draw dashed lines between different representations on y-axis
|
| 188 |
+
yticks = ax.get_yticks()
|
| 189 |
+
for ytick in yticks:
|
| 190 |
+
ax.hlines(ytick + 0.5, -0.1, 1, linestyles='dashed')
|
| 191 |
+
|
| 192 |
+
# Apply color settings to y-axis labels
|
| 193 |
+
set_colors_and_marks_for_representation_groups(ax)
|
| 194 |
+
|
| 195 |
+
# Ensure save directory exists
|
| 196 |
+
os.makedirs(save_path, exist_ok=True)
|
| 197 |
+
|
| 198 |
+
# Save the plot
|
| 199 |
+
filename = os.path.join(save_path, f"{metric}_family_results.png")
|
| 200 |
+
ax.get_figure().savefig(filename, dpi=400, bbox_inches='tight')
|
| 201 |
+
plt.close() # Close the plot to free memory
|
| 202 |
+
|
| 203 |
return filename
|