Flatten namespaces, enable matplotlib headless, use namedtuples.

- import math and matplotlib into current namespace.
- enable matplotlib headless mode.
- Create namedtuples for (x, z) and (x, z, f) pairs.
PEP8 style fixes (break up long lines).