\(iterationFigure[g_, x0_, n_, {x_, xmin_, xmax_}] := 
	
      \((iterates = NestList[g, x0, n - 1]; 
		
        diagonalPts = Transpose[{iterates, iterates}]; 
		
        curvePts = Transpose[{iterates, Map[g, iterates]}]; 
		
        vertlines = Map[Line, Transpose[{diagonalPts, curvePts}]]; 
	\ \ \ 
        horizlines = 
          Map[Line, 
            Transpose[{Drop[diagonalPts, 1], Drop[curvePts, \(-1\)]}]]; 

        	\ \ \ Plot[{x, g[x]}, {x, xmin, xmax}, 
          PlotStyle -> {RGBColor[0, 0.5, 0], RGBColor[0, 0, 1]}, 
          Epilog -> {RGBColor[1, 0, 0], vertlines, horizlines}, 
          PlotRange -> {xmin, xmax}])\)\)