slight enhancement to plot functions - now writes to file