@@ -432,28 +432,34 @@ def plot_data(df_data, plot_path):
432432 color = [colors (i ) for i in range (len (group ))],
433433 align = "center" ,
434434 capsize = 5 ,
435+ label = group ["decoder" ],
435436 )
436437
437438 # Set the labels
438439 ax .set_xlabel ("FPS" )
439- ax .set_ylabel ("Decoder" )
440440
441- # Reverse the order of the handles and labels to match the order of the bars
442- handles = [
443- plt .Rectangle ((0 , 0 ), 1 , 1 , color = colors (i )) for i in range (len (group ))
444- ]
445- ax .legend (
446- handles [::- 1 ],
447- group ["decoder" ][::- 1 ],
448- title = "Decoder" ,
449- loc = "upper right" ,
450- )
441+ # No need for y-axis label past the plot on the far left
442+ if col == 0 :
443+ ax .set_ylabel ("Decoder" )
451444
452445 # Remove any empty subplots for videos with fewer combinations
453446 for row in range (len (unique_videos )):
454447 for col in range (video_type_combinations [unique_videos [row ]], max_combinations ):
455448 fig .delaxes (axes [row , col ])
456449
450+ # If we just call fig.legend, we'll get duplicate labels, as each label appears on
451+ # each subplot. We take advantage of dicts having unique keys to de-dupe.
452+ handles , labels = plt .gca ().get_legend_handles_labels ()
453+ unique_labels = dict (zip (labels , handles ))
454+
455+ # Reverse the order of the handles and labels to match the order of the bars
456+ fig .legend (
457+ handles = reversed (unique_labels .values ()),
458+ labels = reversed (unique_labels .keys ()),
459+ frameon = True ,
460+ loc = "right" ,
461+ )
462+
457463 # Adjust layout to avoid overlap
458464 plt .tight_layout ()
459465
0 commit comments