working code for plots 1-3