Plotting function clean up

Factored out most of the function into its own object (record). Will
simplify re-use of the plotting function.