added plt.close() statements to test loop to avoid memory leak issues