我在pyqtgraph中创建了以下图形。它可以正常运行并按应显示的方式显示。import numpy as npimport pyqtgraph as pgimport pyqtgraph.exportersfrom pyqtgraph.Qt import QtCore, QtGuiimport csvimport itertoolsfrom datetime import datetime as dtapp = QtGui.QApplication([])class TimeAxisItem(pg.AxisItem): def tickStrings(self, values, scale, spacing): return [dt.fromtimestamp(value) for value in values]x_vals = [dt(2018, 7, 1, 13, 6, 38), dt(2018, 7, 1, 12, 46, 38), dt(2018, 7, 1, 12, 36, 38), dt(2018, 7, 1, 12, 26, 38), dt(2018, 7, 1, 12, 16, 38), dt(2018, 7, 1, 12, 6, 38), dt(2018, 7, 1, 11, 56, 38), dt(2018, 7, 1, 11, 46, 38), dt(2018, 7, 1, 11, 36, 38), dt(2018, 7, 1, 11, 26, 38), dt(2018, 7, 1, 10, 56, 38), dt(2018, 7, 1, 10, 46, 38), dt(2018, 7, 1, 10, 36, 38)]y_vals = [23.5, 20.8, 28.0, 28.1, 28.0, 27.8, 27.3, 27.2, 25.7, 24.7, 25.0, 25.0, 24.9]date_axis = TimeAxisItem(orientation='bottom')plt = pg.PlotWidget(axisItems = {'bottom': date_axis})# set propertiesplt.setLabel('left', 'Temperature', units='C')plt.setWindowTitle('Temperature over time')plt.plot(x=[x.timestamp() for x in x_vals], y=y_vals, symbol=None, pen='r', symbolPen='r')plt.show() if __name__ == '__main__': import sys if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'): QtGui.QApplication.instance().exec_()但是,当我尝试从某个函数运行它时,它会闪烁然后消失,但pyqt仍在运行。import numpy as npimport pyqtgraph as pgimport pyqtgraph.exportersfrom pyqtgraph.Qt import QtCore, QtGuiimport csvimport itertoolsfrom datetime import datetime as dtapp = QtGui.QApplication([])class TimeAxisItem(pg.AxisItem): def tickStrings(self, values, scale, spacing): return [dt.fromtimestamp(value) for value in values]如何在不崩溃的情况下从函数运行图形?
添加回答
举报
0/150
提交
取消