Code and plot for plot 4