Code and plot for plot 2