Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,10 +22,13 @@ def draw_scatter_plot_similarity(methods_selected, x_metric, y_metric, title):
|
|
| 22 |
df = pd.read_csv(CSV_RESULT_PATH)
|
| 23 |
# Filter the dataframe based on selected methods
|
| 24 |
filtered_df = df[df['method_name'].isin(methods_selected)]
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
# Add a new column to the dataframe for the color
|
| 27 |
filtered_df['color'] = filtered_df['method_name'].apply(get_method_color)
|
| 28 |
-
|
| 29 |
adjust_text_dict = {
|
| 30 |
'expand_text': (1.15, 1.4), 'expand_points': (1.15, 1.25), 'expand_objects': (1.05, 1.5),
|
| 31 |
'expand_align': (1.05, 1.2), 'autoalign': 'xy', 'va': 'center', 'ha': 'center',
|
|
@@ -35,26 +38,29 @@ def draw_scatter_plot_similarity(methods_selected, x_metric, y_metric, title):
|
|
| 35 |
|
| 36 |
# Create the scatter plot using plotnine (ggplot)
|
| 37 |
g = (p9.ggplot(data=filtered_df,
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
)
|
| 52 |
|
| 53 |
-
# Save the plot as an image
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
g.save(filename=filename, dpi=600)
|
| 56 |
-
|
| 57 |
-
return
|
| 58 |
|
| 59 |
def benchmark_plot(benchmark_type, methods_selected, x_metric, y_metric):
|
| 60 |
if benchmark_type == 'flexible':
|
|
|
|
| 22 |
df = pd.read_csv(CSV_RESULT_PATH)
|
| 23 |
# Filter the dataframe based on selected methods
|
| 24 |
filtered_df = df[df['method_name'].isin(methods_selected)]
|
| 25 |
+
|
| 26 |
+
def get_method_color(method):
|
| 27 |
+
return color_dict.get(method, 'black')
|
| 28 |
+
|
| 29 |
# Add a new column to the dataframe for the color
|
| 30 |
filtered_df['color'] = filtered_df['method_name'].apply(get_method_color)
|
| 31 |
+
|
| 32 |
adjust_text_dict = {
|
| 33 |
'expand_text': (1.15, 1.4), 'expand_points': (1.15, 1.25), 'expand_objects': (1.05, 1.5),
|
| 34 |
'expand_align': (1.05, 1.2), 'autoalign': 'xy', 'va': 'center', 'ha': 'center',
|
|
|
|
| 38 |
|
| 39 |
# Create the scatter plot using plotnine (ggplot)
|
| 40 |
g = (p9.ggplot(data=filtered_df,
|
| 41 |
+
mapping=p9.aes(x=x_metric, # Use the selected x_metric
|
| 42 |
+
y=y_metric, # Use the selected y_metric
|
| 43 |
+
color='color', # Use the dynamically generated color
|
| 44 |
+
label='method_name')) # Label each point by the method name
|
| 45 |
+
+ p9.geom_point(position="jitter") # Add points with slight jitter to avoid overlap
|
| 46 |
+
+ p9.geom_text(adjust_text=adjust_text_dict) # Add method names as labels with text adjustments
|
| 47 |
+
+ p9.labs(title=title, x=f"{x_metric} Metric", y=f"{y_metric} Metric") # Dynamic labels for X and Y axes
|
| 48 |
+
+ p9.scale_color_identity() # Use colors directly from the dataframe
|
| 49 |
+
+ p9.theme(legend_position='none',
|
| 50 |
+
figure_size=(10, 10), # Set figure size
|
| 51 |
+
axis_text=p9.element_text(size=10),
|
| 52 |
+
axis_title_x=p9.element_text(size=12),
|
| 53 |
+
axis_title_y=p9.element_text(size=12))
|
| 54 |
)
|
| 55 |
|
| 56 |
+
# Save the plot as an image
|
| 57 |
+
save_path = "./plot_images" # Ensure this folder exists or adjust the path
|
| 58 |
+
os.makedirs(save_path, exist_ok=True) # Create directory if it doesn't exist
|
| 59 |
+
filename = os.path.join(save_path, title.replace(" ", "_") + "_Similarity_Scatter.png")
|
| 60 |
+
|
| 61 |
g.save(filename=filename, dpi=600)
|
| 62 |
+
|
| 63 |
+
return filename
|
| 64 |
|
| 65 |
def benchmark_plot(benchmark_type, methods_selected, x_metric, y_metric):
|
| 66 |
if benchmark_type == 'flexible':
|