鱼C论坛

 找回密码
 立即注册
查看: 2439|回复: 1

怎么在pyqt5 上刷新 折线图

[复制链接]
发表于 2021-1-11 20:20:34 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
如题  有新的数据进来
然后 刷新图形

  1. from PyQt5.QtWidgets import *
  2. from test import Ui_UiView
  3. import matplotlib
  4. matplotlib.use("Qt5Agg")  # 声明使用QT5
  5. from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
  6. from matplotlib.figure import Figure
  7. from realTimeStockPicMoni import *



  8. from threading import Thread
  9. import time
  10. from PyQt5 import sip
  11. from threading import Timer

  12. class MyFigure(FigureCanvas):
  13.     def __init__(self, width=5, height=4, dpi=100):
  14.         # 创建一个Figure
  15.         self.fig = Figure(figsize=(width, height), dpi=dpi)
  16.         # 在父类中激活Figure窗口
  17.         super(MyFigure, self).__init__(self.fig)
  18.         # 创建一个子图, 用于绘制图形用,111表示子图编号,如matlab的subplot(1,1,1)
  19.         self.axes = self.fig.add_subplot(111)

  20. class OpenView(QMainWindow, Ui_UiView):
  21.     def __init__(self, time_code):
  22.         self.time_code = time_code
  23.         super(OpenView, self).__init__()
  24.         self.setupUi(self)
  25.         self.setWindowTitle('分时图数据')
  26.         self.setMinimumSize(0, 0)
  27.         self.gridlayout = QGridLayout(self.groupBox)  # 继承容器groupBox

  28.         self.show_df()

  29.     def show_df(self):
  30.         self.time_code = str(self.time_code) + '.csv'      # 获取文件名
  31.         time_path = self.time_code.split('_')[0]
  32.         self.path = f'..\\data\\tick\\{time_path}\\{self.time_code}'
  33.         print(self.path)

  34.         self.all_tick = pd.read_csv(self.path)
  35.         self.x = np.arange(0, self.all_tick.index[-1]+1)

  36.         self.F = MyFigure(width=5, height=4, dpi=100)
  37.         self.F.axes.plot(self.x, self.all_tick.close[self.x], self.x, self.all_tick.minu[self.x])
  38.         self.F.axes.set_title("sincos")
  39.         self.gridlayout.addWidget(self.F, 0, 1)



  40.     def foo(self):
  41.         time.sleep(2)
  42.         if self.gridlayout.count() > 0:
  43.             self.gridlayout.removeWidget(self.F)
  44.             self.F.deleteLater()



  45.     #
  46.     #     time.sleep(2)
  47.     #     self.F.axes.plot(self.x, self.all_tick.close[self.x], self.x, self.all_tick.minu[self.x])
  48.     #     # self.gridlayout.addWidget(self.F, 0, 1)
  49.     #     self.show()  # 显示图片


  50.         # time.sleep(0.5)





  51. if __name__ == '__main__':
  52.     app = QApplication(sys.argv)
  53.     time_code = '20210111_000661'
  54.     start = OpenView(time_code)
  55.     start.show()

  56.     t = Timer(5, start.foo)
  57.     t.start()
  58.     sys.exit(app.exec_())
复制代码


有大佬能改吗   万分感谢
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2021-1-11 22:10:51 | 显示全部楼层
while 接收
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-29 06:36

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表