|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
如题 有新的数据进来
然后 刷新图形
- from PyQt5.QtWidgets import *
- from test import Ui_UiView
- import matplotlib
- matplotlib.use("Qt5Agg") # 声明使用QT5
- from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
- from matplotlib.figure import Figure
- from realTimeStockPicMoni import *
- from threading import Thread
- import time
- from PyQt5 import sip
- from threading import Timer
- class MyFigure(FigureCanvas):
- def __init__(self, width=5, height=4, dpi=100):
- # 创建一个Figure
- self.fig = Figure(figsize=(width, height), dpi=dpi)
- # 在父类中激活Figure窗口
- super(MyFigure, self).__init__(self.fig)
- # 创建一个子图, 用于绘制图形用,111表示子图编号,如matlab的subplot(1,1,1)
- self.axes = self.fig.add_subplot(111)
- class OpenView(QMainWindow, Ui_UiView):
- def __init__(self, time_code):
- self.time_code = time_code
- super(OpenView, self).__init__()
- self.setupUi(self)
- self.setWindowTitle('分时图数据')
- self.setMinimumSize(0, 0)
- self.gridlayout = QGridLayout(self.groupBox) # 继承容器groupBox
- self.show_df()
- def show_df(self):
- self.time_code = str(self.time_code) + '.csv' # 获取文件名
- time_path = self.time_code.split('_')[0]
- self.path = f'..\\data\\tick\\{time_path}\\{self.time_code}'
- print(self.path)
- self.all_tick = pd.read_csv(self.path)
- self.x = np.arange(0, self.all_tick.index[-1]+1)
- self.F = MyFigure(width=5, height=4, dpi=100)
- self.F.axes.plot(self.x, self.all_tick.close[self.x], self.x, self.all_tick.minu[self.x])
- self.F.axes.set_title("sincos")
- self.gridlayout.addWidget(self.F, 0, 1)
- def foo(self):
- time.sleep(2)
- if self.gridlayout.count() > 0:
- self.gridlayout.removeWidget(self.F)
- self.F.deleteLater()
- #
- # time.sleep(2)
- # self.F.axes.plot(self.x, self.all_tick.close[self.x], self.x, self.all_tick.minu[self.x])
- # # self.gridlayout.addWidget(self.F, 0, 1)
- # self.show() # 显示图片
- # time.sleep(0.5)
- if __name__ == '__main__':
- app = QApplication(sys.argv)
- time_code = '20210111_000661'
- start = OpenView(time_code)
- start.show()
- t = Timer(5, start.foo)
- t.start()
- sys.exit(app.exec_())
复制代码
有大佬能改吗 万分感谢 |
|