Refactor some of the logic in the plotting script using a variable for the directory, and converting some repeated logic into a loop.

It is far from complete and needs testing.

Signed-off-by: Shawn Laffan <shawnlaffan@gmail.com>