refactored plotutil.py