Update analysis.py

made into a function and set to save images