code and plot for plot4