我正在使用PyQt4运行一些代码,并且我想绘制一个使用其数据的图。但是,当我尝试这样做,它会报告无法同时运行matplotlib和pyqt4
QPixmap: Must construct a QGuiApplication before a QPixmap
下面是代码:
from PyQt4 import QtCore
import sys
import matplotlib.pyplot as plt
import numpy as np
def run():
#here is some code, I delete them since they are useless for this question
return data1 #data1 is a list with 30 elements
app = QtCore.QCoreApplication(sys.argv)
client.finished.connect(app.quit)
QtCore.QTimer().singleShot(0,lambda:client.timed_range_stream(5000))
app.exec_()
fig = plt.figure()
ax1 = fig.add_subplot(111)
data2 = run()
datalen = np.linspace(0,10,len(data2))
ax1.plot(datalen,data2,lw = 2)
plt.show()
由于matplotlib使用PyQt4的作为后端,我很困惑,为什么这个错误发生。它应该自动创建一个QGuiApplication。我的意思是我是否在之前使用pyqt4,'app.exec_()'下面的代码应该自动创建一个QGuiApplication。请指出我是否错了。
非常感谢您的帮助!请给我一些建议。
非常感谢!我很快就会把你的。 – disccip