Plot functions and python optimisation