Use profiler
Profilers can be used to identify sub-optimal parts of code. How much time is spent in which function, how much memory is used where... This is probably not a huge issue for plotID, but can be tried out. Maybe we find possible improvements.
For Python "cProfile" is probably the way to go.