move matplotlib imports to relevant functions