Code and plot for plot2.