def _set_mpl_backend():
    try:
        import matplotlib
    except ImportError:
        if (importlib.util.find_spec('pytest') is not None):
            from .._utils.testing import skip_if_running_tests
            skip_if_running_tests('matplotlib not installed')
        raise
    else:
        from ..version import _import_module_with_version_check, OPTIONAL_MATPLOTLIB_MIN_VERSION
        _import_module_with_version_check('matplotlib', OPTIONAL_MATPLOTLIB_MIN_VERSION)
        current_backend = matplotlib.get_backend().lower()
        if (('inline' in current_backend) or ('nbagg' in current_backend)):
            return
        if ((sys.platform not in ('darwin', 'win32')) and ('DISPLAY' not in os.environ)):
            matplotlib.use('Agg')
def _set_mpl_backend():
    try:
        import matplotlib
    except ImportError:
        if (importlib.util.find_spec('pytest') is not None):
            from .._utils.testing import skip_if_running_tests
            skip_if_running_tests('matplotlib not installed')
        raise
    else:
        from ..version import _import_module_with_version_check, OPTIONAL_MATPLOTLIB_MIN_VERSION
        _import_module_with_version_check('matplotlib', OPTIONAL_MATPLOTLIB_MIN_VERSION)
        current_backend = matplotlib.get_backend().lower()
        if (('inline' in current_backend) or ('nbagg' in current_backend)):
            return
        if ((sys.platform not in ('darwin', 'win32')) and ('DISPLAY' not in os.environ)):
            matplotlib.use('Agg')