为什么matplotlib在Fedora上停止工作?

piah890a  于 2023-05-07  发布在  其他
关注(0)|答案(2)|浏览(225)

我尝试在Fedora上使用matplotlib,但经常收到这样的消息

QSocketNotifier: Can only be used with threads started with QThread

即使有了MWE

import matplotlib.pyplot as plt;
fig = plt.figure();

对于更复杂的脚本,它会抛出分段错误。在Ubuntu上,一切都很好。有人知道这是怎么回事吗?

a8jjtwal

a8jjtwal1#

我在Fedora上使用matplotlib时收到了同样的错误,但它仍然工作正常。

import matplotlib.pyplot as plt
plt.plot([1,2])
plt.show()

/usr/bin/python /home/djohnson/R/Working/foo.py [djohnson@julian Working]$ /usr/bin/python /home/djohnson/R/Working/foo.py QSocketNotifier:只能用于以QThread qt.qpa.wayland启动的线程:Wayland不支持QWindow::requestActivate()
output plot
您是否运行了plt.show()?

6ss1mwsb

6ss1mwsb2#

这是一个警告,告诉你代码试图使用Matplotlib的QT后端绘制一些东西。有更多这样的后端,其中一些是交互式的,一些不是。请参考Matplotlib的各种后端文档。
在非交互式后端(如linux终端)中,函数imshow仍然需要在最后使用show()Jupyter notebook单元格每次默认调用show(),请从源代码中查看此解释。

# This function's signature is rewritten upon backend-load by switch_backend.
def show(*args, **kwargs):
"""
Display all open figures.

Parameters
----------
block : bool, optional
    Whether to wait for all figures to be closed before returning.

    If `True` block and run the GUI main loop until all figure windows
    are closed.

    If `False` ensure that all figure windows are displayed and return
    immediately.  In this case, you are responsible for ensuring
    that the event loop is running to have responsive figures.

    Defaults to True in non-interactive mode and to False in interactive
    mode (see `.pyplot.isinteractive`).

See Also
--------
ion : Enable interactive mode, which shows / updates the figure after
      every plotting command, so that calling ``show()`` is not necessary.
ioff : Disable interactive mode.
savefig : Save the figure to an image file instead of showing it on screen.

Notes
-----
**Saving figures to file and showing a window at the same time**

If you want an image file as well as a user interface window, use
`.pyplot.savefig` before `.pyplot.show`. At the end of (a blocking)
``show()`` the figure is closed and thus unregistered from pyplot. Calling
`.pyplot.savefig` afterwards would save a new and thus empty figure. This
limitation of command order does not apply if the show is non-blocking or
if you keep a reference to the figure and use `.Figure.savefig`.

**Auto-show in jupyter notebooks**

The jupyter backends (activated via ``%matplotlib inline``,
``%matplotlib notebook``, or ``%matplotlib widget``), call ``show()`` at
the end of every cell by default. Thus, you usually don't have to call it
explicitly there.
"""

相关问题