Fix imports and skip specific tests if matplotlib is not installed