Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,22 +8,61 @@ import json
|
|
8 |
import yaml
|
9 |
import matplotlib.pyplot as plt
|
10 |
import seaborn as sns
|
|
|
11 |
|
12 |
from src.about import *
|
13 |
from src.bin.PROBE import run_probe
|
14 |
|
15 |
global data_component, filter_component
|
16 |
|
|
|
|
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
def benchmark_plot(benchmark_type, methods_selected, x_metric, y_metric):
|
20 |
-
if benchmark_type == '
|
21 |
# Use general visualizer logic
|
22 |
return general_visualizer_plot(methods_selected, x_metric=x_metric, y_metric=y_metric)
|
23 |
-
elif benchmark_type == '
|
24 |
-
|
25 |
-
|
26 |
-
return benchmark_2_plot(x_metric, y_metric)
|
27 |
elif benchmark_type == 'Benchmark 3':
|
28 |
return benchmark_3_plot(x_metric, y_metric)
|
29 |
elif benchmark_type == 'Benchmark 4':
|
|
|
8 |
import yaml
|
9 |
import matplotlib.pyplot as plt
|
10 |
import seaborn as sns
|
11 |
+
import plotnine as p9
|
12 |
|
13 |
from src.about import *
|
14 |
from src.bin.PROBE import run_probe
|
15 |
|
16 |
global data_component, filter_component
|
17 |
|
18 |
+
def get_method_color(method):
|
19 |
+
return color_dict.get(method, 'black') # If method is not in color_dict, use black
|
20 |
|
21 |
+
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',
|
32 |
+
'force_text': (.0, 1.), 'force_objects': (.0, 1.),
|
33 |
+
'lim': 500000, 'precision': 1., 'avoid_points': True, 'avoid_text': True
|
34 |
+
}
|
35 |
+
|
36 |
+
# Create the scatter plot using plotnine (ggplot)
|
37 |
+
g = (p9.ggplot(data=filtered_df,
|
38 |
+
mapping=p9.aes(x=x_metric, # Use the selected x_metric
|
39 |
+
y=y_metric, # Use the selected y_metric
|
40 |
+
color='color', # Use the dynamically generated color
|
41 |
+
label='method_name')) # Label each point by the method name
|
42 |
+
+ p9.geom_point(position="jitter") # Add points with slight jitter to avoid overlap
|
43 |
+
+ p9.geom_text(adjust_text=adjust_text_dict) # Add method names as labels with text adjustments
|
44 |
+
+ p9.labs(title=title, x=f"{x_metric} Metric", y=f"{y_metric} Metric") # Dynamic labels for X and Y axes
|
45 |
+
+ p9.scale_color_identity() # This tells plotnine to use the exact color values from the dataframe
|
46 |
+
+ p9.theme(legend_position='none',
|
47 |
+
figure_size=(10, 10), # Set figure size
|
48 |
+
axis_text=p9.element_text(size=10),
|
49 |
+
axis_title_x=p9.element_text(size=12),
|
50 |
+
axis_title_y=p9.element_text(size=12))
|
51 |
+
)
|
52 |
+
|
53 |
+
# Save the plot as an image (you can modify save_path accordingly)
|
54 |
+
filename = title.replace(" ", "_") + "_Similarity_Scatter.png" # Save the plot
|
55 |
+
g.save(filename=filename, dpi=600)
|
56 |
+
|
57 |
+
return g
|
58 |
|
59 |
def benchmark_plot(benchmark_type, methods_selected, x_metric, y_metric):
|
60 |
+
if benchmark_type == 'flexible':
|
61 |
# Use general visualizer logic
|
62 |
return general_visualizer_plot(methods_selected, x_metric=x_metric, y_metric=y_metric)
|
63 |
+
elif benchmark_type == 'similarity':
|
64 |
+
title = f"Similarity Benchmark: {x_metric} vs {y_metric}"
|
65 |
+
return draw_scatter_plot(methods_selected, x_metric, y_metric, title)
|
|
|
66 |
elif benchmark_type == 'Benchmark 3':
|
67 |
return benchmark_3_plot(x_metric, y_metric)
|
68 |
elif benchmark_type == 'Benchmark 4':
|