human
Complete the below
def install_repl_displayhook():

    ''''Install a repl display hook so that any stale figure are automatically
    redrawn when control is returned to the repl.
    This works with IPython terminals and kernels,
    as well as vanilla python shells.'
    '''
 Write me a the Python code you requested?
assistant
#Here is the Python code you requested.
    global _IP_REGISTERED
    global _INSTALL_FIG_OBSERVER
    class _NotIPython(Exception, ):
        pass
    try:
        if (u'IPython' in sys.modules):
            from IPython import get_ipython
            ip = get_ipython()
            if (ip is None):
                raise _NotIPython()
            if _IP_REGISTERED:
                return
            def post_execute():
                if matplotlib.is_interactive():
                    draw_all()
            try:
                ip.events.register(u'post_execute', post_execute)
            except AttributeError:
                ip.register_post_execute(post_execute)
            _IP_REGISTERED = post_execute
            _INSTALL_FIG_OBSERVER = False
            from IPython.core.pylabtools import backend2gui
            ipython_gui_name = backend2gui.get(get_backend())
            if ipython_gui_name:
                ip.enable_gui(ipython_gui_name)
        else:
            _INSTALL_FIG_OBSERVER = True
    except (ImportError, _NotIPython):
        _INSTALL_FIG_OBSERVER = True