<commit_before>class MatplotlibBackendSetter(object):
    """
    Import hook to make sure the proper Qt backend is set when importing
    Matplotlib.
    """

    enabled = True

    def find_module(self, mod_name, pth):
        if self.enabled and 'matplotlib' in mod_name:
            self.enabled = False
            set_mpl_backend()

    def find_spec(self, name, import_path, target_module=None):
        pass

def set_mpl_backend():

    from matplotlib import rcParams, rcdefaults

    # standardize mpl setup
    rcdefaults()

    from qtpy import PYQT5

    if PYQT5:
        rcParams['backend'] = 'Qt5Agg'<commit_msg>Make sure set_mpl_backend works if qtpy is not installed<commit_after>class MatplotlibBackendSetter(object):
    """
    Import hook to make sure the proper Qt backend is set when importing
    Matplotlib.
    """

    enabled = True

    def find_module(self, mod_name, pth):
        if self.enabled and 'matplotlib' in mod_name:
            self.enabled = False
            set_mpl_backend()

    def find_spec(self, name, import_path, target_module=None):
        pass

def set_mpl_backend():

    try:
        from qtpy import PYQT5
    except:
        # If Qt isn't available, we don't have to worry about
        # setting the backend
        return

    from matplotlib import rcParams, rcdefaults

    # standardize mpl setup
    rcdefaults()

    if PYQT5:
        rcParams['backend'] = 'Qt5Agg'
{'fraction_non_alphanumeric': 0.0732728541521284, 'fraction_numerical': 0.00418702023726448, 'mean_word_length': 2.593984962406015, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4078742', 'n_tokens_mistral': 453, 'n_tokens_neox': 423, 'n_words': 135}