def fix_display(self):
        """If this is being run on a headless system the Matplotlib
        backend must be changed to one that doesn't need a display.
        """

        try:
            tkinter.Tk()
        except (tkinter.TclError, NameError): # If there is no display.
            try:
                import matplotlib as mpl
            except ImportError:
                pass
            else:
                print("Setting matplotlib backend to Agg")
                mpl.use('Agg')
If this is being run on a headless system the Matplotlib
        backend must be changed to one that doesn't need a display.