Repository: ipython/ipython

Issue:
`%matplotlib` + qt5
Support for qt5 was just merged into matplotlib master (https://github.com/matplotlib/matplotlib/pull/3072), however due to the way that `pylabtools` deals with parsing the backend the `%matplotlib` magic does not work correctly with the `Qt5Agg` backend.



Discussion:

Resolving patch:
diff --git a/IPython/core/pylabtools.py b/IPython/core/pylabtools.py
--- a/IPython/core/pylabtools.py
+++ b/IPython/core/pylabtools.py
@@ -1,24 +1,9 @@
 # -*- coding: utf-8 -*-
-"""Pylab (matplotlib) support utilities.
-
-Authors
--------
-
-* Fernando Perez.
-* Brian Granger
-"""
+"""Pylab (matplotlib) support utilities."""
 from __future__ import print_function
 
-#-----------------------------------------------------------------------------
-#  Copyright (C) 2009  The IPython Development Team
-#
-#  Distributed under the terms of the BSD License.  The full license is in
-#  the file COPYING, distributed as part of this software.
-#-----------------------------------------------------------------------------
-
-#-----------------------------------------------------------------------------
-# Imports
-#-----------------------------------------------------------------------------
+# Copyright (c) IPython Development Team.
+# Distributed under the terms of the Modified BSD License.
 
 from io import BytesIO
 
@@ -34,7 +19,9 @@
             'wx': 'WXAgg',
             'qt': 'Qt4Agg', # qt3 not supported
             'qt4': 'Qt4Agg',
+            'qt5': 'Qt5Agg',
             'osx': 'MacOSX',
+            'nbagg': 'nbAgg',
             'inline' : 'module://IPython.kernel.zmq.pylab.backend_inline'}
 
 # We also need a reverse backends2guis mapping that will properly choose which
diff --git a/IPython/kernel/zmq/eventloops.py b/IPython/kernel/zmq/eventloops.py
--- a/IPython/kernel/zmq/eventloops.py
+++ b/IPython/kernel/zmq/eventloops.py
@@ -1,33 +1,18 @@
 # encoding: utf-8
-"""Event loop integration for the ZeroMQ-based kernels.
-"""
+"""Event loop integration for the ZeroMQ-based kernels."""
 
-#-----------------------------------------------------------------------------
-#  Copyright (C) 2011  The IPython Development Team
-
-#  Distributed under the terms of the BSD License.  The full license is in
-#  the file COPYING, distributed as part of this software.
-#-----------------------------------------------------------------------------
-
-
-#-----------------------------------------------------------------------------
-# Imports
-#-----------------------------------------------------------------------------
+# Copyright (c) IPython Development Team.
+# Distributed under the terms of the Modified BSD License.
 
+import os
 import sys
 
-# System library imports
 import zmq
 
-# Local imports
 from IPython.config.application import Application
 from IPython.utils import io
 
 
-#------------------------------------------------------------------------------
-# Eventloops for integrating the Kernel into different GUIs
-#------------------------------------------------------------------------------
-
 def _on_os_x_10_9():
     import platform
     from distutils.version import LooseVersion as V
@@ -54,6 +39,7 @@ def process_stream_events():
 # mapping of keys to loop functions
 loop_map = {
     'inline': None,
+    'nbagg': None,
     None : None,
 }
 
@@ -92,6 +78,12 @@ def loop_qt4(kernel):
     
     start_event_loop_qt4(kernel.app)
 
+@register_integration('qt5')
+def loop_qt5(kernel):
+    """Start a kernel with PyQt5 event loop integration."""
+    os.environ['QT_API'] = 'pyqt5'
+    return loop_qt4(kernel)
+
 
 @register_integration('wx')
 def loop_wx(kernel):


Test patch: