eud*_*xos 5 backend matplotlib
我正在运行编写的代码PyQt4
,使用matplotlib的Qt4Agg
后端在Windows中显示实时图.同时,我想在后台线程中使用matplotlib来生成(不同的)数字,这些数字只保存到文件中,而不是显示在屏幕上.
我可以Qt4Agg
在后台线程中使用,但我得到了一堆
QPixmap: It is not safe to use pixmaps outside the GUI thread
Run Code Online (Sandbox Code Playgroud)
警告,在某些情况下也会崩溃.
据我所知,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')
Run Code Online (Sandbox Code Playgroud)
HTH