1+ import matplotlib .pyplot as plt
2+ import os
3+
4+ # Data points for formats (Redundancy, Convenience)
5+ formats = {
6+ "Clang AST" : (0.9 , 0.0 ), # High redundancy, low convenience
7+ "XML" : (0 , 0.1 ), # Slightly more redundancy and convenience
8+ "Asciidoc" : (0.8 , 0.8 ), # Higher convenience, higher redundancy
9+ "HTML" : (0.9 , 1.0 ), # Most convenient, slightly more redundant
10+ "Custom Templates" : (0.5 , 0.6 ), # Most convenient, slightly more redundant
11+ }
12+
13+ # Hypothetical solutions behind the Pareto front
14+ hypotheticals = [(0.4 , 0.05 ), (0.45 , 0.05 ), (0.7 , 0.2 ), (0.9 , 0.45 ), (1 , 0.35 )]
15+
16+ # Plotting
17+ plt .figure (figsize = (8 , 6 ))
18+
19+
20+ def calculate_pareto_front (data_points ):
21+ # Sort data points by the x-coordinate
22+ data_points .sort ()
23+
24+ # Calculate the Pareto front
25+ pareto_front = []
26+ max_y = float ('-inf' )
27+ for x , y in data_points :
28+ if y > max_y :
29+ pareto_front .append ((x , y ))
30+ max_y = y
31+
32+ # Create stairs for the Pareto front
33+ min_x = min (data_points , key = lambda x : x [0 ])[0 ]
34+ max_x = max (data_points , key = lambda x : x [0 ])[0 ]
35+ min_y = min (data_points , key = lambda x : x [1 ])[1 ]
36+ max_y = max (data_points , key = lambda x : x [1 ])[1 ]
37+ stairs_x = [min_x ]
38+ stairs_y = [min_y ]
39+ for i in range (len (pareto_front ) - 1 ):
40+ stairs_x .extend ([pareto_front [i ][0 ], pareto_front [i + 1 ][0 ]])
41+ stairs_y .extend ([pareto_front [i ][1 ], pareto_front [i ][1 ]])
42+ stairs_x .append (pareto_front [- 1 ][0 ])
43+ stairs_y .append (pareto_front [- 1 ][1 ])
44+ stairs_x .append (max_x )
45+ stairs_y .append (max_y )
46+
47+ return stairs_x , stairs_y
48+
49+
50+ data_points = list (formats .values ()) + hypotheticals
51+ pareto_x , pareto_y = calculate_pareto_front (data_points )
52+ plt .plot (pareto_x , pareto_y , linestyle = "--" , color = "gray" , label = "Best Trade-offs" )
53+
54+ # Hypothetical solutions
55+ x_hyp , y_hyp = zip (* hypotheticals )
56+ plt .scatter (x_hyp , y_hyp , color = "gray" , alpha = 0.5 , label = "Hypothetical" )
57+
58+ for label , (x , y ) in formats .items ():
59+ plt .scatter (x , y , s = 100 )
60+ plt .annotate (label , (x , y ), textcoords = "offset points" , xytext = (5 , 5 ), ha = 'center' )
61+
62+ # The ideal solution
63+ plt .scatter (0 , 1 , color = "gray" , alpha = 0.5 )
64+ plt .annotate ("Ideal" , (0 , 1 ), textcoords = "offset points" , xytext = (5 , 5 ), ha = 'center' )
65+
66+ # Labels and Legend
67+ plt .xlabel ("Redundancy" )
68+ plt .ylabel ("Convenience" )
69+ plt .title ("Output Formats" )
70+ plt .legend ()
71+ plt .grid (True )
72+ plt .xticks ([])
73+ plt .yticks ([])
74+
75+ # Get the directory of the script
76+ script_dir = os .path .dirname (__file__ )
77+
78+ # Construct the target path
79+ target_path = os .path .join (script_dir , '../modules/ROOT/images/generator_front.svg' )
80+
81+ # Save the plot to the target path
82+ plt .savefig (target_path )
0 commit comments