refactor psth plot into function