improve graph code for data plotting