Code and plot for plot 3