larray-project / larray-editor

Graphical User Interface for LArray
GNU General Public License v3.0
2 stars 2 forks source link

Plots via the console are broken #278

Closed gdementen closed 2 months ago

gdementen commented 2 months ago

Plots via Ctrl-P work fine, but the plot commands in the console are not displayed:

>>> arr = ndtest((3, 4))
>>> arr.plot()

I suppose this is due to a matplotlib update. Sigh...

When running from within a script, we see the traceback:

Traceback (most recent call last):
  File "c:\users\gdm\devel\larray-editor\larray_editor\editor.py", line 737, in ipython_cell_executed
    show_figure(self, first_output.figure, last_input)
  File "c:\users\gdm\devel\larray-editor\larray_editor\utils.py", line 302, in show_figure
    figure.canvas.manager.window is not None):
AttributeError: 'FigureManagerBase' object has no attribute 'window'
gdementen commented 2 months ago

I am getting crazy over this one. I have been going back as far as matplotlib 3.3.4 (earliest version with conda package available for Python 3.9) and they all fail with the above error message, while my "dev38" environment which has matplotlib 3.7.2 works. I don't understand what else than matplotlib can change the available attributes.

gdementen commented 2 months ago

Just when I thought I had found the most obscure bug of the year with #277. This one beats it hands down. The culprit seems to be an update to xlwings. I still have no idea how this can possibly have an impact on matplotlib structures, but with xlwings 0.24.x several of my environments work while with xlwings 0.31.4, they don't. I am curious to know what the **** is actually happening.

gdementen commented 2 months ago

xlwings 0.29.1 works too

gdementen commented 2 months ago

Found the culprit. xlwings 0.31.4 added this code:

import matplotlib as mpl
import matplotlib.figure  # noqa: F401
import matplotlib.pyplot as plt

# https://matplotlib.org/stable/users/explain/figure/backends.html#static-backends
# This prevents "Starting a Matplotlib GUI outside of the main thread will likely
# fail." with xlwings Server
mpl.use("agg")

See: https://github.com/xlwings/xlwings/pull/2445

I guess we will need to set an explicit backend ourselves. Unsure it should be done before or after importing xlwings though.