[script][figure] Fix bug with histo legends and add comments/doc in the code

4 jobs for fixlegends in 13 minutes and 25 seconds (queued for 5 seconds)
Status Name Job ID Coverage
  Build
passed build_linux_27 #140565
docker

00:13:20

86.0%
passed build_linux_36 #140566
docker

00:13:15

86.0%
passed build_macosx_27 #140567
macosx

00:09:25

86.0%
passed build_macosx_36 #140568
macosx

00:11:07

86.0%