code and plot for plot2