%pylabplot([0,1])
tight_layout()
# happens same way in object modefrommatplotlibimportpylabaspltfig, ax=plt.subplots()
ax.plot([0,1])
fig.tight_layout()
Actual outcome
below another example from real code that may be instructive
Expected outcome
figure scaled to image size, background deleted.
Additional information
Happens always.
I do not recall this issue in version before 3.5
I have no clue why it is happening. The flaw seems to lay in mpl getting/setting wrong window size when using tight_layout. Maybe gtk unhappy with X11. When I use mpl.use('Qt5Cairo') then it just makes the window and fonts smaller. Obviously, tight_layout should not change physical window size on screen! Similar for Gtk4Cairo. Gtk4Agg has similar issues to Qt5Agg but does not retain noise in background, just shrinks figure. I could be related to DPI settings. It might get them from a different system call than when opening the window?
The only fix I can find is use other plot package, e.g., plotly.
Operating system
Linux 5.16.14-200.fc35.x86_64 #1 SMP PREEMPT Fri Mar 11 20:31:18 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Are you using a window tiling manager? Perhaps it is doing weird things with the window dpi. Tight layout doesn't change window size but it does do multiple draws. I suspect somehow that between the draws your window manager is telling matplotlib that the dpi or dpi ratio has changed.
No, just regular windows.
I have never seen it before mpl Version 3.4.
It always changes from original window when I call tinge_layout the first time in a window.
it theon only plots in the smaller fraction of the window, or the shrunk window.
when I resize window thereafter, it fills the window, but retains the smaller font.
So it seems tight_layout gets dpi from somewhere else - wrongly and new to mpl 3.5+ - from the initial call, and then sets it permanently.
specifically, it sets dpi to 72 whereas the original value is 102.
72 seems to be default value, so something is broken and ut uses default over actual value.
In [13]: plot([0,1])
Out[13]: [<matplotlib.lines.Line2D at 0x7f3a4c9d5c60>]
In [14]: gcf().dpi
Out[14]: 100.0
In [15]: tight_layout()
In [16]: gcf().dpi
Out[16]: 72
Python 3.10.2 (main, Jan 28 2022, 00:32:56) [GCC 11.2.1 20211203 (Red Hat 11.2.1-7)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.1.1 -- An enhanced Interactive Python. Type '?' for help.
Using matplotlib backend: Qt5Agg
%pylab is deprecated, use %matplotlib inline and import the required libraries.
Populating the interactive namespace from numpy and matplotlib
In [1]: plot([0,1])
Out[1]: [<matplotlib.lines.Line2D at 0x7ff89f71a2c0>]
In [2]: from matplotlib.backend_bases import _get_renderer
In [3]: renderer = _get_renderer(gcf())
In [4]: renderer.dpi
Out[4]: 100.0
In [5]: tight_layout()
In [6]: gcf().dpi
Out[6]: 72
In [7]: renderer.dpi
Out[7]: 100.0
Something is changing your dpi_ratio between the draw triggered by plot and the draw triggered by tight_layout. I would be very surprised if this had anything to do with tight_layout per-se. Rather I think that the first call doesn't really know the dpi or dpi_ratio until the first window is made, and then it gets updated, and the subsequent window is resized.
If I use plt.ion(), I cannot reproduce your problem on MacOS.
I think you first analysis is not correct. The resolution of 100 dpi it uses first is the correct one. The 72 dpi is a default value it must be getting elsewhere. From xdpyinfo:
screen #0:
dimensions: 3840x2160 pixels (1016x571 millimeters)
resolution: 96x96 dots per inch
In [1]: mpl.__version__Out[1]: '3.6.0.dev1932+gbda8790ca1'
With this, the dpi issue is gone, but the plot is no longer automatically updated in pylab (ion) mode. I need to call plt.pause(...) manually to update the plot.
Python 3.10.2 (main, Jan 28 2022, 00:32:56) [GCC 11.2.1 20211203 (Red Hat 11.2.1-7)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.2.0 -- An enhanced Interactive Python. Type '?' for help.
Using matplotlib backend: QtAgg
%pylab is deprecated, use %matplotlib inline and import the required libraries.
Populating the interactive namespace from numpy and matplotlib
In [1]: plot([0,1])
Out[1]: [<matplotlib.lines.Line2D at 0x7fd25c6a2650>]
In [2]: tight_layout()
In [3]: pause(.1)
In [4]: plt.gcf().dpi
Out[4]: 100.0
so, one bug fixed, one new ... :-(
Maybe the old pyparsing causes issues with IPython. ... No, it is not. Must be something else. It seem I just need to call plt.ion() manually now (can be accommodated in ipython config or startup file). All else works.
I did some conda updates (lidely including matplotlib) and I unfortunately just had the same problem displaying plots. I had to downgrade to matplotlib=3.4.3=py38hecd8cb5_0 to make it work again.
@agallenne please open a new issue perhaps after creating a fresh conda environment. Be sure to include all details of your setup and steps to reproduce the problem. Thanks.
I can't install properly matplotlib apparently. I did conda create -n py39 python=3.9 matplotlib, but I now have another error:
`Python 3.9.12 (main, Jun 1 2022, 06:36:29)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.3.0 -- An enhanced Interactive Python. Type '?' for help.
[TerminalIPythonApp] WARNING | Eventloop or matplotlib integration failed. Is matplotlib installed?
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3526, in InteractiveShell.enable_pylab(self, gui, import_all, welcome_message)
3499 """Activate pylab support at runtime.
3500
3501 This turns on support for matplotlib, preloads into the interactive
(...)
3522 This argument is ignored, no welcome message will be displayed.
3523 """
3524 from IPython.core.pylabtools import import_pylab
-> 3526 gui, backend = self.enable_matplotlib(gui)
3528 # We want to prevent the loading of pylab to pollute the user's
3529 # namespace as shown by the %who* magics, so we execute the activation
3530 # code in an empty namespace, and we update both user_ns and
3531 # user_ns_hidden with this information.
3532 ns = {}
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3487, in InteractiveShell.enable_matplotlib(self, gui)
3483 print('Warning: Cannot change to a different GUI toolkit: %s.'
3484 ' Using %s instead.' % (gui, self.pylab_gui_select))
3485 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
-> 3487 pt.activate_matplotlib(backend)
3488 configure_inline_support(self, backend)
3490 # Now we must activate the gui pylab wants to use, and fix %run to take
3491 # plot updates into account
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/IPython/core/pylabtools.py:357, in activate_matplotlib(backend)
352 matplotlib.rcParams['backend'] = backend
354 # Due to circular imports, pyplot may be only partially initialised
355 # when this function runs.
356 # So avoid needing matplotlib attribute-lookup to access pyplot.
--> 357 from matplotlib import pyplot as plt
359 plt.switch_backend(backend)
361 plt.show._needmain = False
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:2230, in
2228 dict.setitem(rcParams, "backend", rcsetup._auto_backend_sentinel)
2229 # Set up the backend.
-> 2230 switch_backend(rcParams["backend"])
2232 # Just to be safe. Interactive mode can be turned on without
2233 # calling plt.ion() so register it again here.
2234 # This is safe because multiple calls to install_repl_displayhook
2235 # are no-ops and the registered function respect mpl.is_interactive()
2236 # to determine if they should trigger a draw.
2237 install_repl_displayhook()
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:267, in switch_backend(newbackend)
260 # Backends are implemented as modules, but "inherit" default method
261 # implementations from backend_bases._Backend. This is achieved by
262 # creating a "class" that inherits from backend_bases._Backend and whose
263 # body is filled with the module's globals.
265 backend_name = cbook._backend_module_name(newbackend)
--> 267 class backend_mod(matplotlib.backend_bases._Backend):
268 locals().update(vars(importlib.import_module(backend_name)))
270 required_framework = _get_required_interactive_framework(backend_mod)
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:268, in switch_backend..backend_mod()
267 class backend_mod(matplotlib.backend_bases._Backend):
--> 268 locals().update(vars(importlib.import_module(backend_name)))
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/backend_qt5agg.py:5, in
1 """
2 Render to qt from agg
3 """
----> 5 from .backend_qtagg import (
6 _BackendQTAgg, FigureCanvasQTAgg, FigureManagerQT, NavigationToolbar2QT,
7 backend_version, FigureCanvasAgg, FigureCanvasQT
8 )
11 @_BackendQTAgg.export
12 class _BackendQT5Agg(_BackendQTAgg):
13 pass
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/backend_qtagg.py:9, in
5 import ctypes
7 from matplotlib.transforms import Bbox
----> 9 from .qt_compat import QT_API, _enum, _setDevicePixelRatio
10 from .. import cbook
11 from .backend_agg import FigureCanvasAgg
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/qt_compat.py:128, in
126 break
127 else:
--> 128 raise ImportError("Failed to import any qt binding")
129 else: # We should not get there.
130 raise AssertionError(f"Unexpected QT_API: {QT_API}")
ImportError: Failed to import any qt binding
[TerminalIPythonApp] WARNING | Unknown error in handling startup files:
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/IPython/core/interactiveshell.py:2737, in InteractiveShell.safe_execfile(self, fname, exit_ignore, raise_exceptions, shell_futures, *where)
2735 try:
2736 glob, loc = (where + (None, ))[:2]
-> 2737 py3compat.execfile(
2738 fname, glob, loc,
2739 self.compile if shell_futures else None)
2740 except SystemExit as status:
2741 # If the call was made with 0 or None exit status (sys.exit(0)
2742 # or sys.exit() ), don't bother showing a traceback, as both of
(...)
2748 # For other exit status, we show the exception unless
2749 # explicitly silenced, but only in short form.
2750 if status.code:
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/IPython/utils/py3compat.py:55, in execfile(fname, glob, loc, compiler)
53 with open(fname, "rb") as f:
54 compiler = compiler or compile
---> 55 exec(compiler(f.read(), fname, "exec"), glob, loc)
File ~/.ipython/profile_default/startup/startup_funtions.py:7, in
4 pass
6 import astropy.units as units
----> 7 from uncertainties import ufloat, umath
ModuleNotFoundError: No module named 'uncertainties'`
This file is run as part of IPython start up, but is controlled by you:
File ~/.ipython/profile_default/startup/startup_funtions.py:7, in
4 pass
6 import astropy.units as units
----> 7 from uncertainties import ufloat, umath
You need to keep installing things until you have all of the libraries you need or remove stuff from your start up file if you no longer need it.
yes I know, sorry I pasted everything, it was more the first lines actually, saying "[TerminalIPythonApp] WARNING | Eventloop or matplotlib integration failed. Is matplotlib installed?"
Then if I want to plot I can't because if I do "import matplotlib.pyplot as plt" I have this:
In [2]: import matplotlib.pyplot as plt
ImportError Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 import matplotlib.pyplot as plt
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:2230, in
2228 dict.setitem(rcParams, "backend", rcsetup._auto_backend_sentinel)
2229 # Set up the backend.
-> 2230 switch_backend(rcParams["backend"])
2232 # Just to be safe. Interactive mode can be turned on without
2233 # calling plt.ion() so register it again here.
2234 # This is safe because multiple calls to install_repl_displayhook
2235 # are no-ops and the registered function respect mpl.is_interactive()
2236 # to determine if they should trigger a draw.
2237 install_repl_displayhook()
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:267, in switch_backend(newbackend)
260 # Backends are implemented as modules, but "inherit" default method
261 # implementations from backend_bases._Backend. This is achieved by
262 # creating a "class" that inherits from backend_bases._Backend and whose
263 # body is filled with the module's globals.
265 backend_name = cbook._backend_module_name(newbackend)
--> 267 class backend_mod(matplotlib.backend_bases._Backend):
268 locals().update(vars(importlib.import_module(backend_name)))
270 required_framework = _get_required_interactive_framework(backend_mod)
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:268, in switch_backend..backend_mod()
267 class backend_mod(matplotlib.backend_bases._Backend):
--> 268 locals().update(vars(importlib.import_module(backend_name)))
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/backend_qt5agg.py:5, in
1 """
2 Render to qt from agg
3 """
----> 5 from .backend_qtagg import (
6 _BackendQTAgg, FigureCanvasQTAgg, FigureManagerQT, NavigationToolbar2QT,
7 backend_version, FigureCanvasAgg, FigureCanvasQT
8 )
11 @_BackendQTAgg.export
12 class _BackendQT5Agg(_BackendQTAgg):
13 pass
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/backend_qtagg.py:9, in
5 import ctypes
7 from matplotlib.transforms import Bbox
----> 9 from .qt_compat import QT_API, _enum, _setDevicePixelRatio
10 from .. import cbook
11 from .backend_agg import FigureCanvasAgg
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/qt_compat.py:128, in
126 break
127 else:
--> 128 raise ImportError("Failed to import any qt binding")
129 else: # We should not get there.
130 raise AssertionError(f"Unexpected QT_API: {QT_API}")
ImportError: Failed to import any qt binding
In [3]: import matplotlib
In [4]: import matplotlib.pyplot as plt
ImportError Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 import matplotlib.pyplot as plt
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:2230, in
2228 dict.setitem(rcParams, "backend", rcsetup._auto_backend_sentinel)
2229 # Set up the backend.
-> 2230 switch_backend(rcParams["backend"])
2232 # Just to be safe. Interactive mode can be turned on without
2233 # calling plt.ion() so register it again here.
2234 # This is safe because multiple calls to install_repl_displayhook
2235 # are no-ops and the registered function respect mpl.is_interactive()
2236 # to determine if they should trigger a draw.
2237 install_repl_displayhook()
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:267, in switch_backend(newbackend)
260 # Backends are implemented as modules, but "inherit" default method
261 # implementations from backend_bases._Backend. This is achieved by
262 # creating a "class" that inherits from backend_bases._Backend and whose
263 # body is filled with the module's globals.
265 backend_name = cbook._backend_module_name(newbackend)
--> 267 class backend_mod(matplotlib.backend_bases._Backend):
268 locals().update(vars(importlib.import_module(backend_name)))
270 required_framework = _get_required_interactive_framework(backend_mod)
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:268, in switch_backend..backend_mod()
267 class backend_mod(matplotlib.backend_bases._Backend):
--> 268 locals().update(vars(importlib.import_module(backend_name)))
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/backend_qt5agg.py:5, in
1 """
2 Render to qt from agg
3 """
----> 5 from .backend_qtagg import (
6 _BackendQTAgg, FigureCanvasQTAgg, FigureManagerQT, NavigationToolbar2QT,
7 backend_version, FigureCanvasAgg, FigureCanvasQT
8 )
11 @_BackendQTAgg.export
12 class _BackendQT5Agg(_BackendQTAgg):
13 pass
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/backend_qtagg.py:9, in
5 import ctypes
7 from matplotlib.transforms import Bbox
----> 9 from .qt_compat import QT_API, _enum, _setDevicePixelRatio
10 from .. import cbook
11 from .backend_agg import FigureCanvasAgg
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/qt_compat.py:128, in
126 break
127 else:
--> 128 raise ImportError("Failed to import any qt binding")
129 else: # We should not get there.
130 raise AssertionError(f"Unexpected QT_API: {QT_API}")
Not sure to understand. I am not asking for help about installing matplotlib. I just add problem to have a fresh py39 install (as you asked). But I figured it out and saw that I still have the problem with tight_layout, as the original post.
Activity
2sn commented on Mar 20, 2022
TkAgg and WxAgg give same (broken) results.
jklymak commented on Mar 20, 2022
Are you using a window tiling manager? Perhaps it is doing weird things with the window dpi. Tight layout doesn't change window size but it does do multiple draws. I suspect somehow that between the draws your window manager is telling matplotlib that the dpi or dpi ratio has changed.
2sn commented on Mar 20, 2022
No, just regular windows.
I have never seen it before mpl Version 3.4.
It always changes from original window when I call tinge_layout the first time in a window.
it theon only plots in the smaller fraction of the window, or the shrunk window.
when I resize window thereafter, it fills the window, but retains the smaller font.
So it seems tight_layout gets dpi from somewhere else - wrongly and new to mpl 3.5+ - from the initial call, and then sets it permanently.
2sn commented on Mar 20, 2022
specifically, it sets dpi to 72 whereas the original value is 102.
72 seems to be default value, so something is broken and ut uses default over actual value.
2sn commented on Mar 20, 2022
2sn commented on Mar 20, 2022
Another interesting example
Oops.
QuLogic commented on Mar 24, 2022
I cannot reproduce either of these effects.
QuLogic commented on Mar 24, 2022
Also, you probably shouldn't use this any more.
2sn commented on Mar 24, 2022
I am using IPython on the command line, not jupyter.
What was/is wrong with %pylab?
It seemed to have worked find and still does.
2sn commented on Mar 24, 2022
@QuLogic
does not work.
timhoffm commented on Mar 24, 2022
jklymak commented on Mar 24, 2022
Something is changing your dpi_ratio between the draw triggered by plot and the draw triggered by tight_layout. I would be very surprised if this had anything to do with tight_layout per-se. Rather I think that the first call doesn't really know the dpi or dpi_ratio until the first window is made, and then it gets updated, and the subsequent window is resized.
If I use plt.ion(), I cannot reproduce your problem on MacOS.
try
jklymak commented on Mar 24, 2022
Other debugging steps:
let us know your window manager and any settings you have for it, including your dpi_ratio
make sure you do not have any settings in your matplotlibrc (move it somewhere else for now).
test as a script without interactive mode on.
2sn commented on Mar 24, 2022
I think you first analysis is not correct. The resolution of 100 dpi it uses first is the correct one. The 72 dpi is a default value it must be getting elsewhere. From xdpyinfo:
50 remaining items
2sn commented on Mar 30, 2022
@jklymak Thanks ... seems to uninstall some existing things
Installing collected packages: pyparsing, matplotlib Attempting uninstall: pyparsing Found existing installation: pyparsing 3.0.7 Uninstalling pyparsing-3.0.7: Successfully uninstalled pyparsing-3.0.7 Attempting uninstall: matplotlib Found existing installation: matplotlib 3.5.1 Uninstalling matplotlib-3.5.1: Successfully uninstalled matplotlib-3.5.1 Running setup.py develop for matplotlib Successfully installed matplotlib-3.6.0.dev1932+gbda8790ca1 pyparsing-2.4.7and I have
With this, the dpi issue is gone, but the plot is no longer automatically updated in pylab (ion) mode. I need to call plt.pause(...) manually to update the plot.
so, one bug fixed, one new ... :-(
Maybe the old pyparsing causes issues with IPython. ... No, it is not. Must be something else. It seem I just need to call plt.ion() manually now (can be accommodated in ipython config or startup file). All else works.
agallenne commented on Jun 3, 2022
I did some conda updates (lidely including matplotlib) and I unfortunately just had the same problem displaying plots. I had to downgrade to matplotlib=3.4.3=py38hecd8cb5_0 to make it work again.
jklymak commented on Jun 3, 2022
@agallenne please open a new issue perhaps after creating a fresh conda environment. Be sure to include all details of your setup and steps to reproduce the problem. Thanks.
agallenne commented on Jun 13, 2022
By doing Conda update all?
jklymak commented on Jun 13, 2022
I would create a new environment: https://docs.conda.io/projects/conda/en/latest/user-guide/tasks/manage-environments.html
agallenne commented on Jun 13, 2022
I can't install properly matplotlib apparently. I did conda create -n py39 python=3.9 matplotlib, but I now have another error:
`Python 3.9.12 (main, Jun 1 2022, 06:36:29)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.3.0 -- An enhanced Interactive Python. Type '?' for help.
[TerminalIPythonApp] WARNING | Eventloop or matplotlib integration failed. Is matplotlib installed?
ImportError Traceback (most recent call last)
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/IPython/core/shellapp.py:235, in InteractiveShellApp.init_gui_pylab..(key)
233 shell = self.shell
234 if self.pylab:
--> 235 enable = lambda key: shell.enable_pylab(key, import_all=self.pylab_import_all)
236 key = self.pylab
237 elif self.matplotlib:
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3526, in InteractiveShell.enable_pylab(self, gui, import_all, welcome_message)
3499 """Activate pylab support at runtime.
3500
3501 This turns on support for matplotlib, preloads into the interactive
(...)
3522 This argument is ignored, no welcome message will be displayed.
3523 """
3524 from IPython.core.pylabtools import import_pylab
-> 3526 gui, backend = self.enable_matplotlib(gui)
3528 # We want to prevent the loading of pylab to pollute the user's
3529 # namespace as shown by the %who* magics, so we execute the activation
3530 # code in an empty namespace, and we update both user_ns and
3531 # user_ns_hidden with this information.
3532 ns = {}
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/IPython/core/interactiveshell.py:3487, in InteractiveShell.enable_matplotlib(self, gui)
3483 print('Warning: Cannot change to a different GUI toolkit: %s.'
3484 ' Using %s instead.' % (gui, self.pylab_gui_select))
3485 gui, backend = pt.find_gui_and_backend(self.pylab_gui_select)
-> 3487 pt.activate_matplotlib(backend)
3488 configure_inline_support(self, backend)
3490 # Now we must activate the gui pylab wants to use, and fix %run to take
3491 # plot updates into account
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/IPython/core/pylabtools.py:357, in activate_matplotlib(backend)
352 matplotlib.rcParams['backend'] = backend
354 # Due to circular imports, pyplot may be only partially initialised
355 # when this function runs.
356 # So avoid needing matplotlib attribute-lookup to access pyplot.
--> 357 from matplotlib import pyplot as plt
359 plt.switch_backend(backend)
361 plt.show._needmain = False
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:2230, in
2228 dict.setitem(rcParams, "backend", rcsetup._auto_backend_sentinel)
2229 # Set up the backend.
-> 2230 switch_backend(rcParams["backend"])
2232 # Just to be safe. Interactive mode can be turned on without
2233 # calling plt.ion() so register it again here.
2234 # This is safe because multiple calls to install_repl_displayhook
2235 # are no-ops and the registered function respect mpl.is_interactive()
2236 # to determine if they should trigger a draw.
2237 install_repl_displayhook()
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:267, in switch_backend(newbackend)
260 # Backends are implemented as modules, but "inherit" default method
261 # implementations from backend_bases._Backend. This is achieved by
262 # creating a "class" that inherits from backend_bases._Backend and whose
263 # body is filled with the module's globals.
265 backend_name = cbook._backend_module_name(newbackend)
--> 267 class backend_mod(matplotlib.backend_bases._Backend):
268 locals().update(vars(importlib.import_module(backend_name)))
270 required_framework = _get_required_interactive_framework(backend_mod)
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:268, in switch_backend..backend_mod()
267 class backend_mod(matplotlib.backend_bases._Backend):
--> 268 locals().update(vars(importlib.import_module(backend_name)))
File ~/opt/anaconda3/envs/py39/lib/python3.9/importlib/init.py:127, in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/backend_qt5agg.py:5, in
1 """
2 Render to qt from agg
3 """
----> 5 from .backend_qtagg import (
6 _BackendQTAgg, FigureCanvasQTAgg, FigureManagerQT, NavigationToolbar2QT,
7 backend_version, FigureCanvasAgg, FigureCanvasQT
8 )
11 @_BackendQTAgg.export
12 class _BackendQT5Agg(_BackendQTAgg):
13 pass
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/backend_qtagg.py:9, in
5 import ctypes
7 from matplotlib.transforms import Bbox
----> 9 from .qt_compat import QT_API, _enum, _setDevicePixelRatio
10 from .. import cbook
11 from .backend_agg import FigureCanvasAgg
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/qt_compat.py:128, in
126 break
127 else:
--> 128 raise ImportError("Failed to import any qt binding")
129 else: # We should not get there.
130 raise AssertionError(f"Unexpected QT_API: {QT_API}")
ImportError: Failed to import any qt binding
[TerminalIPythonApp] WARNING | Unknown error in handling startup files:
ModuleNotFoundError Traceback (most recent call last)
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/IPython/core/shellapp.py:360, in InteractiveShellApp._exec_file(self, fname, shell_futures)
356 self.shell.safe_execfile_ipy(full_filename,
357 shell_futures=shell_futures)
358 else:
359 # default to python, even without extension
--> 360 self.shell.safe_execfile(full_filename,
361 self.shell.user_ns,
362 shell_futures=shell_futures,
363 raise_exceptions=True)
364 finally:
365 sys.argv = save_argv
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/IPython/core/interactiveshell.py:2737, in InteractiveShell.safe_execfile(self, fname, exit_ignore, raise_exceptions, shell_futures, *where)
2735 try:
2736 glob, loc = (where + (None, ))[:2]
-> 2737 py3compat.execfile(
2738 fname, glob, loc,
2739 self.compile if shell_futures else None)
2740 except SystemExit as status:
2741 # If the call was made with 0 or None exit status (sys.exit(0)
2742 # or sys.exit() ), don't bother showing a traceback, as both of
(...)
2748 # For other exit status, we show the exception unless
2749 # explicitly silenced, but only in short form.
2750 if status.code:
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/IPython/utils/py3compat.py:55, in execfile(fname, glob, loc, compiler)
53 with open(fname, "rb") as f:
54 compiler = compiler or compile
---> 55 exec(compiler(f.read(), fname, "exec"), glob, loc)
File ~/.ipython/profile_default/startup/startup_funtions.py:7, in
4 pass
6 import astropy.units as units
----> 7 from uncertainties import ufloat, umath
ModuleNotFoundError: No module named 'uncertainties'`
tacaswell commented on Jun 13, 2022
This file is run as part of IPython start up, but is controlled by you:
You need to keep installing things until you have all of the libraries you need or remove stuff from your start up file if you no longer need it.
This discussion is probably better had at https://discourse.matplotlib.org rather than the issue tracker.
agallenne commented on Jun 13, 2022
yes I know, sorry I pasted everything, it was more the first lines actually, saying "[TerminalIPythonApp] WARNING | Eventloop or matplotlib integration failed. Is matplotlib installed?"
Then if I want to plot I can't because if I do "import matplotlib.pyplot as plt" I have this:
In [2]: import matplotlib.pyplot as plt
ImportError Traceback (most recent call last)
Input In [2], in <cell line: 1>()
----> 1 import matplotlib.pyplot as plt
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:2230, in
2228 dict.setitem(rcParams, "backend", rcsetup._auto_backend_sentinel)
2229 # Set up the backend.
-> 2230 switch_backend(rcParams["backend"])
2232 # Just to be safe. Interactive mode can be turned on without
2233 # calling plt.ion() so register it again here.
2234 # This is safe because multiple calls to install_repl_displayhook
2235 # are no-ops and the registered function respect mpl.is_interactive()
2236 # to determine if they should trigger a draw.
2237 install_repl_displayhook()
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:267, in switch_backend(newbackend)
260 # Backends are implemented as modules, but "inherit" default method
261 # implementations from backend_bases._Backend. This is achieved by
262 # creating a "class" that inherits from backend_bases._Backend and whose
263 # body is filled with the module's globals.
265 backend_name = cbook._backend_module_name(newbackend)
--> 267 class backend_mod(matplotlib.backend_bases._Backend):
268 locals().update(vars(importlib.import_module(backend_name)))
270 required_framework = _get_required_interactive_framework(backend_mod)
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:268, in switch_backend..backend_mod()
267 class backend_mod(matplotlib.backend_bases._Backend):
--> 268 locals().update(vars(importlib.import_module(backend_name)))
File ~/opt/anaconda3/envs/py39/lib/python3.9/importlib/init.py:127, in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/backend_qt5agg.py:5, in
1 """
2 Render to qt from agg
3 """
----> 5 from .backend_qtagg import (
6 _BackendQTAgg, FigureCanvasQTAgg, FigureManagerQT, NavigationToolbar2QT,
7 backend_version, FigureCanvasAgg, FigureCanvasQT
8 )
11 @_BackendQTAgg.export
12 class _BackendQT5Agg(_BackendQTAgg):
13 pass
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/backend_qtagg.py:9, in
5 import ctypes
7 from matplotlib.transforms import Bbox
----> 9 from .qt_compat import QT_API, _enum, _setDevicePixelRatio
10 from .. import cbook
11 from .backend_agg import FigureCanvasAgg
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/qt_compat.py:128, in
126 break
127 else:
--> 128 raise ImportError("Failed to import any qt binding")
129 else: # We should not get there.
130 raise AssertionError(f"Unexpected QT_API: {QT_API}")
ImportError: Failed to import any qt binding
In [3]: import matplotlib
In [4]: import matplotlib.pyplot as plt
ImportError Traceback (most recent call last)
Input In [4], in <cell line: 1>()
----> 1 import matplotlib.pyplot as plt
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:2230, in
2228 dict.setitem(rcParams, "backend", rcsetup._auto_backend_sentinel)
2229 # Set up the backend.
-> 2230 switch_backend(rcParams["backend"])
2232 # Just to be safe. Interactive mode can be turned on without
2233 # calling plt.ion() so register it again here.
2234 # This is safe because multiple calls to install_repl_displayhook
2235 # are no-ops and the registered function respect mpl.is_interactive()
2236 # to determine if they should trigger a draw.
2237 install_repl_displayhook()
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:267, in switch_backend(newbackend)
260 # Backends are implemented as modules, but "inherit" default method
261 # implementations from backend_bases._Backend. This is achieved by
262 # creating a "class" that inherits from backend_bases._Backend and whose
263 # body is filled with the module's globals.
265 backend_name = cbook._backend_module_name(newbackend)
--> 267 class backend_mod(matplotlib.backend_bases._Backend):
268 locals().update(vars(importlib.import_module(backend_name)))
270 required_framework = _get_required_interactive_framework(backend_mod)
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/pyplot.py:268, in switch_backend..backend_mod()
267 class backend_mod(matplotlib.backend_bases._Backend):
--> 268 locals().update(vars(importlib.import_module(backend_name)))
File ~/opt/anaconda3/envs/py39/lib/python3.9/importlib/init.py:127, in import_module(name, package)
125 break
126 level += 1
--> 127 return _bootstrap._gcd_import(name[level:], package, level)
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/backend_qt5agg.py:5, in
1 """
2 Render to qt from agg
3 """
----> 5 from .backend_qtagg import (
6 _BackendQTAgg, FigureCanvasQTAgg, FigureManagerQT, NavigationToolbar2QT,
7 backend_version, FigureCanvasAgg, FigureCanvasQT
8 )
11 @_BackendQTAgg.export
12 class _BackendQT5Agg(_BackendQTAgg):
13 pass
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/backend_qtagg.py:9, in
5 import ctypes
7 from matplotlib.transforms import Bbox
----> 9 from .qt_compat import QT_API, _enum, _setDevicePixelRatio
10 from .. import cbook
11 from .backend_agg import FigureCanvasAgg
File ~/opt/anaconda3/envs/py39/lib/python3.9/site-packages/matplotlib/backends/qt_compat.py:128, in
126 break
127 else:
--> 128 raise ImportError("Failed to import any qt binding")
129 else: # We should not get there.
130 raise AssertionError(f"Unexpected QT_API: {QT_API}")
ImportError: Failed to import any qt binding
agallenne commented on Jun 13, 2022
Ok I installed PyQt5, let's see steps further
agallenne commented on Jun 13, 2022
No, same problem with a fresh env
jklymak commented on Jun 13, 2022
This is not an appropriate forum for user help. Please take to discourse.matplotlib.org and we can try and help. Thanks for your understanding!
agallenne commented on Jun 14, 2022
Not sure to understand. I am not asking for help about installing matplotlib. I just add problem to have a fresh py39 install (as you asked). But I figured it out and saw that I still have the problem with tight_layout, as the original post.
jklymak commented on Jun 14, 2022
I you have this issue, and you have a fresh install, please open a new issue with all the relevant details. The dev team cannot reproduce the original issue, so please be sure to give us the magic formula to make it happen. (Also please have a look at how to format code on GitHub: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#quoting-code)