gpt4 book ai didi

matplotlib - 在一个程序中使用交互式和非交互式后端

转载 作者:行者123 更新时间:2023-12-04 18:43:56 25 4
gpt4 key购买 nike

我正在运行用 PyQt4 编写的代码它使用 matplotlib 的 Qt4Agg用于在 Windows 中显示实时绘图的后端。同时,我想在后台线程中使用 matplotlib 来生成(不同的)图形,这些图形只保存到文件中,而不显示在屏幕上。

我可以用 Qt4Agg在后台线程中,但我得到了一堆

QPixmap: It is not safe to use pixmaps outside the GUI thread

警告,在某些情况下也会崩溃。

据我所知,matplotlib 目前支持在任何给定时间只使用一个后端(可以通过 switch_backend 更改,但这会关闭所有现有数字)。有没有办法解决这个限制,并分配每个数字的后端?

最佳答案

据我所知,只有当您不使用 pyplot 界面时。

例如,将完整的 OO 界面用于简单绘图:

from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure

fig = Figure()
canvas = FigureCanvas(fig)
ax = fig.add_subplot(1,1,1)
ax.plot([1,2,3])
canvas.print_figure('test.png')

HTH

关于matplotlib - 在一个程序中使用交互式和非交互式后端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18207563/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com