convert plot code to a proper script