Repository navigation
Description
Currently, when users select qt with %gui qt or %matplotlib qt, IPython forces matplotlib to switch to Qt5Agg first, before matplotlib's qt_compat.py kicks in (which, if run on its own, can actually pick up the right Qt bindings installed).
ipython/IPython/core/pylabtools.py
Line 26 in 396593e
| "qt": "Qt5Agg", |
ipython/IPython/core/pylabtools.py
Lines 301 to 322 in 396593e
| def find_gui_and_backend(gui=None, gui_select=None): | |
| """Given a gui string return the gui and mpl backend. | |
| Parameters | |
| ---------- | |
| gui : str | |
| Can be one of ('tk','gtk','wx','qt','qt4','inline','agg'). | |
| gui_select : str | |
| Can be one of ('tk','gtk','wx','qt','qt4','inline'). | |
| This is any gui already selected by the shell. | |
| Returns | |
| ------- | |
| A tuple of (gui, backend) where backend is one of ('TkAgg','GTKAgg', | |
| 'WXAgg','Qt4Agg','module://matplotlib_inline.backend_inline','agg'). | |
| """ | |
| import matplotlib | |
| if gui and gui != 'auto': | |
| # select backend based on requested gui | |
| backend = backends[gui] |
This isn't documented and has caused me a lot of confusion and trouble (and will cause further trouble in the future as usage of Qt6 increases over Qt5):
- https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-matplotlib
- https://ipython.readthedocs.io/en/stable/interactive/magics.html#magic-gui
I found out about this after spending months trying to work out why %matplotlib qt doesn't work when I have Qt6 bindings installed: matplotlib/matplotlib#25673 (comment)
I suggest we either explicitly document this in the IPython line magic docs, or we change this default behavior.
Relevant but not duplicate:
Activity
kwsp commentedon Apr 26, 2023
relevant comment from @tacaswell: #13859 (comment)
By the way @tacaswell thank you I appreciate your great work on matplotlib (and
qt_compat.py)IPython defaulting to
Qt5Aggwhen users selectqtcompletely sidesteps most of the logic inqt_compat.pywhich actually works!kwsp commentedon Apr 28, 2023
took a look at the docs again and i'd say this is actually a bug
tacaswell commentedon Apr 28, 2023
I will advocate for a PR that changes L26 to
QtAgg. It probably requires a bit of version gating on the version of Matplotlib for versions before and after we added theQtAggbackend.Gullumluvl commentedon Jul 12, 2023
Maybe related: in Ipython 8.14.0, running
%matplotlib tkalso prints "Installed qt5 event loop hook", as in issue #14006 . And then plots do not appear, except for a flashing instant when callingplt.close()...