Code for generating graphs