为了账号安全,请及时绑定邮箱和手机立即绑定

从函数运行pyqtgraph

从函数运行pyqtgraph

Helenr 2021-04-05 16:23:11
我在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]如何在不崩溃的情况下从函数运行图形?
查看完整描述

2 回答

?
慕斯王

TA贡献1864条经验 获得超2个赞

在main()内调用Gshow()


查看完整回答
反对 回复 2021-04-27
  • 2 回答
  • 0 关注
  • 238 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信