8
8
from typing import Any
9
9
10
10
import matplotlib .pyplot as plt
11
- import numpy as np
12
11
import pandas as pd
12
+ import seaborn as sns
13
13
14
14
# Configure logging
15
15
logging .basicConfig (
@@ -138,37 +138,31 @@ def plot_speedup_distribution(
138
138
plt .close ()
139
139
return
140
140
141
+ # Set seaborn style for better aesthetics
142
+ sns .set_style ("whitegrid" )
143
+ sns .set_context ("paper" , font_scale = 1.1 )
144
+
145
+ palette = sns .color_palette ("tab10" , 4 )
146
+ hist_color = palette [0 ] # Blue
147
+ top_color = palette [2 ] # Green
148
+ bottom_color = palette [3 ] # Red
149
+
141
150
# Create figure with three subplots
142
- fig = plt .figure (figsize = (15 , 5 ))
151
+ fig = plt .figure (figsize = (15 , 6. 5 )) # Increased height for better spacing
143
152
gs = plt .GridSpec (1 , 3 , width_ratios = [1.5 , 1 , 1 ])
144
153
ax1 = fig .add_subplot (gs [0 ])
145
154
ax2 = fig .add_subplot (gs [1 ])
146
155
ax3 = fig .add_subplot (gs [2 ])
147
156
148
- # Use colorblind-friendly colors
149
- hist_color = "#4878D0" # Blue
150
- top_color = "#60BD68" # Green
151
- bottom_color = "#EE6677" # Red
152
-
153
157
# 1. Histogram of typical speedups (< max_speedup)
154
158
typical_speedups = comparison_df [comparison_df ["Speedup" ] < max_speedup ]["Speedup" ]
155
159
156
160
if len (typical_speedups ) > 0 :
157
- ax1 .hist (typical_speedups , bins = 15 , color = hist_color , alpha = 0.7 , edgecolor = "black" )
158
- ax1 .axvline (
159
- typical_speedups .median (),
160
- color = "#404040" ,
161
- linestyle = "--" ,
162
- linewidth = 1.5 ,
163
- label = f"Median: { typical_speedups .median ():.2f} x" ,
164
- )
165
- ax1 .axvline (1 , color = "#404040" , linestyle = ":" , linewidth = 1.5 , alpha = 0.7 , label = "No speedup (1x)" )
166
- ax1 .grid (True , alpha = 0.3 )
161
+ sns .histplot (typical_speedups , bins = 15 , color = hist_color , alpha = 0.7 , edgecolor = "black" , ax = ax1 )
167
162
168
163
ax1 .set_xlabel ("Speedup (x)" , fontsize = 12 )
169
164
ax1 .set_ylabel ("Number of transforms" , fontsize = 12 )
170
- ax1 .set_title (f"(a) Distribution of Typical Speedups\n (< { max_speedup } x)" , fontsize = 14 )
171
- ax1 .legend (fontsize = 10 )
165
+ ax1 .set_title (f"(a) Distribution of Speedups < { max_speedup } x" , fontsize = 14 )
172
166
else :
173
167
ax1 .text (0.5 , 0.5 , "No speedup data < 20x" , ha = "center" , va = "center" , fontsize = 12 )
174
168
ax1 .set_axis_off ()
@@ -177,24 +171,32 @@ def plot_speedup_distribution(
177
171
top_n = min (10 , len (comparison_df ))
178
172
if top_n > 0 :
179
173
top_10 = comparison_df .nlargest (top_n , "Speedup" )
180
- bars = ax2 .barh (np .arange (len (top_10 )), top_10 ["Speedup" ], color = top_color , alpha = 0.7 , edgecolor = "black" )
181
- ax2 .set_yticks (np .arange (len (top_10 )))
182
- ax2 .set_yticklabels (top_10 ["Transform" ], fontsize = 10 )
174
+ sns .barplot (
175
+ x = "Speedup" ,
176
+ y = "Transform" ,
177
+ data = top_10 ,
178
+ color = top_color ,
179
+ alpha = 0.7 ,
180
+ edgecolor = "black" ,
181
+ ax = ax2 ,
182
+ )
183
183
ax2 .grid (True , alpha = 0.3 )
184
184
185
- for _ , bar in enumerate ( bars ):
186
- width = bar . get_width ()
185
+ # Add text labels for speedup values
186
+ for i , v in enumerate ( top_10 [ "Speedup" ]):
187
187
ax2 .text (
188
- width + 0.05 ,
189
- bar . get_y () + bar . get_height () / 2 ,
190
- f"{ width :.2f} x" ,
188
+ v + 0.05 ,
189
+ i ,
190
+ f"{ v :.2f} x" ,
191
191
ha = "left" ,
192
192
va = "center" ,
193
193
fontsize = 10 ,
194
194
bbox = {"facecolor" : "white" , "alpha" : 0.8 , "edgecolor" : "none" },
195
195
)
196
196
197
197
ax2 .set_xlabel ("Speedup (x)" , fontsize = 12 )
198
+ # Remove y-label "Transform"
199
+ ax2 .set_ylabel ("" )
198
200
ax2 .set_title ("(b) Top 10 Speedups" , fontsize = 14 )
199
201
else :
200
202
ax2 .text (0.5 , 0.5 , "No speedup data" , ha = "center" , va = "center" , fontsize = 12 )
@@ -204,30 +206,32 @@ def plot_speedup_distribution(
204
206
bottom_n = min (10 , len (comparison_df ))
205
207
if bottom_n > 0 :
206
208
bottom_10 = comparison_df .nsmallest (bottom_n , "Speedup" )
207
- bars = ax3 .barh (
208
- np .arange (len (bottom_10 )),
209
- bottom_10 ["Speedup" ],
209
+ sns .barplot (
210
+ x = "Speedup" ,
211
+ y = "Transform" ,
212
+ data = bottom_10 ,
210
213
color = bottom_color ,
211
214
alpha = 0.7 ,
212
215
edgecolor = "black" ,
216
+ ax = ax3 ,
213
217
)
214
- ax3 .set_yticks (np .arange (len (bottom_10 )))
215
- ax3 .set_yticklabels (bottom_10 ["Transform" ], fontsize = 10 )
216
218
ax3 .grid (True , alpha = 0.3 )
217
219
218
- for _ , bar in enumerate ( bars ):
219
- width = bar . get_width ()
220
+ # Add text labels for speedup values
221
+ for i , v in enumerate ( bottom_10 [ "Speedup" ]):
220
222
ax3 .text (
221
- width + 0.05 ,
222
- bar . get_y () + bar . get_height () / 2 ,
223
- f"{ width :.2f} x" ,
223
+ v + 0.05 ,
224
+ i ,
225
+ f"{ v :.2f} x" ,
224
226
ha = "left" ,
225
227
va = "center" ,
226
228
fontsize = 10 ,
227
229
bbox = {"facecolor" : "white" , "alpha" : 0.8 , "edgecolor" : "none" },
228
230
)
229
231
230
232
ax3 .set_xlabel ("Speedup (x)" , fontsize = 12 )
233
+ # Remove y-label "Transform"
234
+ ax3 .set_ylabel ("" )
231
235
ax3 .set_title ("(c) Bottom 10 Speedups" , fontsize = 14 )
232
236
else :
233
237
ax3 .text (0.5 , 0.5 , "No speedup data" , ha = "center" , va = "center" , fontsize = 12 )
@@ -256,23 +260,28 @@ def plot_speedup_distribution(
256
260
f"{ total_transforms } transforms with multiple library support"
257
261
)
258
262
259
- # Add the stats text to the bottom right of the figure
263
+ # Add the stats text to the right side of the left plot with larger font
264
+ ax1_pos = ax1 .get_position ()
265
+ # Calculate 10% of the plot width
266
+ plot_width = ax1_pos .x1 - ax1_pos .x0
267
+ shift_amount = plot_width * 0.1
268
+
260
269
plt .figtext (
261
- 0.98 ,
262
- 0.02 ,
270
+ ax1_pos . x1 - 0.02 - shift_amount , # Shifted left by 10% of plot width
271
+ ax1_pos . y1 - 0.02 , # Slightly below the top edge of the left plot
263
272
stats_text ,
264
273
ha = "right" ,
265
- va = "bottom " ,
266
- bbox = {"facecolor" : "white" , "alpha" : 0.9 , "edgecolor" : "none " },
267
- fontsize = 10 ,
274
+ va = "top " ,
275
+ bbox = {"facecolor" : "white" , "alpha" : 0.9 , "edgecolor" : "lightgray" , "boxstyle" : "round,pad=0.5 " },
276
+ fontsize = 14 , # Significantly increased font size
268
277
)
269
278
270
- # Add title with information about the reference library
271
- plt .suptitle (f"Speedup Analysis: { reference_library .capitalize ()} vs Other Libraries" , fontsize = 16 )
279
+ # Add title with information about the reference library with more space
280
+ plt .suptitle (f"Speedup Analysis: { reference_library .capitalize ()} vs Other Libraries" , fontsize = 16 , y = 1.02 )
272
281
273
282
# Adjust layout and save
274
283
plt .tight_layout ()
275
- plt .subplots_adjust (top = 0.9 , bottom = 0.15 ) # Make room for the suptitle and stats
284
+ plt .subplots_adjust (top = 0.88 ) # Increased top margin for suptitle
276
285
plt .savefig (output_path , dpi = 300 , bbox_inches = "tight" )
277
286
plt .close ()
278
287
0 commit comments