Code and plot for plot4.