Spaces:
Running
Running
Update src/vis_utils.py
Browse files- src/vis_utils.py +20 -22
src/vis_utils.py
CHANGED
|
@@ -26,13 +26,13 @@ def benchmark_plot(benchmark_type, methods_selected, x_metric, y_metric, aspect,
|
|
| 26 |
if benchmark_type == 'similarity':
|
| 27 |
return plot_similarity_results(methods_selected, x_metric, y_metric)
|
| 28 |
elif benchmark_type == 'function':
|
| 29 |
-
return plot_function_results(aspect, single_metric
|
| 30 |
elif benchmark_type == 'family':
|
| 31 |
-
return plot_family_results(
|
| 32 |
elif benchmark_type == "affinity":
|
| 33 |
-
return plot_affinity_results(
|
| 34 |
-
|
| 35 |
-
|
| 36 |
|
| 37 |
def get_method_color(method):
|
| 38 |
return color_dict.get(method, 'black') # If method is not in color_dict, use black
|
|
@@ -119,7 +119,7 @@ def plot_similarity_results(methods_selected, x_metric, y_metric, similarity_pat
|
|
| 119 |
|
| 120 |
return filename
|
| 121 |
|
| 122 |
-
def plot_function_results(aspect, metric,
|
| 123 |
if not os.path.exists(function_path):
|
| 124 |
benchmark_types = ["similarity", "function", "family", "affinity"] #download all files for faster results later
|
| 125 |
download_from_hub(benchmark_types)
|
|
@@ -168,18 +168,16 @@ def plot_function_results(aspect, metric, method_names, function_path="/tmp/func
|
|
| 168 |
|
| 169 |
return filename
|
| 170 |
|
| 171 |
-
def plot_family_results(
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
|
|
|
|
|
|
|
|
|
| 176 |
df = df[df['Method'].isin(method_names)]
|
| 177 |
-
metric_columns = [col for col in df.columns if col.startswith(f"{metric}_")]
|
| 178 |
-
|
| 179 |
-
# Check if there are columns matching the selected metric
|
| 180 |
-
if not metric_columns:
|
| 181 |
-
print(f"No columns found for metric '{metric}'.")
|
| 182 |
-
return None
|
| 183 |
|
| 184 |
# Reshape data for plotting
|
| 185 |
df_long = pd.melt(df[['Method'] + metric_columns], id_vars=['Method'], var_name='Fold', value_name='Value')
|
|
@@ -204,12 +202,12 @@ def plot_family_results(file_path, method_names, metric, save_path="./plot_image
|
|
| 204 |
ax.hlines(ytick + 0.5, -0.1, 1, linestyles='dashed')
|
| 205 |
|
| 206 |
# Apply color settings to y-axis labels
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
# Save the plot
|
|
|
|
| 213 |
filename = os.path.join(save_path, f"{metric}_family_results.png")
|
| 214 |
ax.get_figure().savefig(filename, dpi=400, bbox_inches='tight')
|
| 215 |
plt.close() # Close the plot to free memory
|
|
|
|
| 26 |
if benchmark_type == 'similarity':
|
| 27 |
return plot_similarity_results(methods_selected, x_metric, y_metric)
|
| 28 |
elif benchmark_type == 'function':
|
| 29 |
+
return plot_function_results(methods_selected, aspect, single_metric)
|
| 30 |
elif benchmark_type == 'family':
|
| 31 |
+
return plot_family_results(methods_selected, dataset, single_metric)
|
| 32 |
elif benchmark_type == "affinity":
|
| 33 |
+
return plot_affinity_results(methods_selected, single_metric)
|
| 34 |
+
else:
|
| 35 |
+
return -1
|
| 36 |
|
| 37 |
def get_method_color(method):
|
| 38 |
return color_dict.get(method, 'black') # If method is not in color_dict, use black
|
|
|
|
| 119 |
|
| 120 |
return filename
|
| 121 |
|
| 122 |
+
def plot_function_results(method_names, aspect, metric, function_path="/tmp/function_results.csv"):
|
| 123 |
if not os.path.exists(function_path):
|
| 124 |
benchmark_types = ["similarity", "function", "family", "affinity"] #download all files for faster results later
|
| 125 |
download_from_hub(benchmark_types)
|
|
|
|
| 168 |
|
| 169 |
return filename
|
| 170 |
|
| 171 |
+
def plot_family_results(methods_selected, dataset, metric, family_path="/tmp/family_results.csv"):
|
| 172 |
+
if not os.path.exists(function_path):
|
| 173 |
+
benchmark_types = ["similarity", "function", "family", "affinity"] #download all files for faster results later
|
| 174 |
+
download_from_hub(benchmark_types)
|
| 175 |
+
|
| 176 |
+
df = pd.read_csv(family_path)
|
| 177 |
+
|
| 178 |
+
# Filter by method names and selected dataset columns
|
| 179 |
df = df[df['Method'].isin(method_names)]
|
| 180 |
+
metric_columns = [col for col in df.columns if col.startswith(f"{dataset}_{metric}_")]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
|
| 182 |
# Reshape data for plotting
|
| 183 |
df_long = pd.melt(df[['Method'] + metric_columns], id_vars=['Method'], var_name='Fold', value_name='Value')
|
|
|
|
| 202 |
ax.hlines(ytick + 0.5, -0.1, 1, linestyles='dashed')
|
| 203 |
|
| 204 |
# Apply color settings to y-axis labels
|
| 205 |
+
for label in ax.get_yticklabels():
|
| 206 |
+
method = label.get_text()
|
| 207 |
+
label.set_color(get_method_color(method))
|
| 208 |
+
|
|
|
|
| 209 |
# Save the plot
|
| 210 |
+
save_path = "/tmp"
|
| 211 |
filename = os.path.join(save_path, f"{metric}_family_results.png")
|
| 212 |
ax.get_figure().savefig(filename, dpi=400, bbox_inches='tight')
|
| 213 |
plt.close() # Close the plot to free memory
|