Write Graph Function

separated output of graph into function