edited to recreate figure for each iteration of the main for loop and also added new return value and pickle dump for all the plot data