@@ -414,28 +414,34 @@ def plot_data(df_data, plot_path):
414
414
color = [colors (i ) for i in range (len (group ))],
415
415
align = "center" ,
416
416
capsize = 5 ,
417
+ label = group ["decoder" ],
417
418
)
418
419
419
420
# Set the labels
420
421
ax .set_xlabel ("FPS" )
421
- ax .set_ylabel ("Decoder" )
422
422
423
- # Reverse the order of the handles and labels to match the order of the bars
424
- handles = [
425
- plt .Rectangle ((0 , 0 ), 1 , 1 , color = colors (i )) for i in range (len (group ))
426
- ]
427
- ax .legend (
428
- handles [::- 1 ],
429
- group ["decoder" ][::- 1 ],
430
- title = "Decoder" ,
431
- loc = "upper right" ,
432
- )
423
+ # No need for y-axis label past the plot on the far left
424
+ if col == 0 :
425
+ ax .set_ylabel ("Decoder" )
433
426
434
427
# Remove any empty subplots for videos with fewer combinations
435
428
for row in range (len (unique_videos )):
436
429
for col in range (video_type_combinations [unique_videos [row ]], max_combinations ):
437
430
fig .delaxes (axes [row , col ])
438
431
432
+ # If we just call fig.legend, we'll get duplicate labels, as each label appears on
433
+ # each subplot. We take advantage of dicts having unique keys to de-dupe.
434
+ handles , labels = plt .gca ().get_legend_handles_labels ()
435
+ unique_labels = dict (zip (labels , handles ))
436
+
437
+ # Reverse the order of the handles and labels to match the order of the bars
438
+ fig .legend (
439
+ handles = reversed (unique_labels .values ()),
440
+ labels = reversed (unique_labels .keys ()),
441
+ frameon = True ,
442
+ loc = "right" ,
443
+ )
444
+
439
445
# Adjust layout to avoid overlap
440
446
plt .tight_layout ()
441
447
0 commit comments