2023-01-14 07:49:53 +01:00
|
|
|
import sys
|
2023-01-14 14:03:15 +01:00
|
|
|
import random
|
2023-01-14 07:49:53 +01:00
|
|
|
import matplotlib
|
|
|
|
matplotlib.use('Qt5Agg')
|
2023-01-15 10:05:41 +01:00
|
|
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
2023-01-14 07:49:53 +01:00
|
|
|
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
|
|
|
|
from matplotlib.figure import Figure
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# twin_plot.py
|
|
|
|
# @title: Visualisation des données
|
|
|
|
# @project: Blender-EduTech
|
|
|
|
# @lang: fr
|
|
|
|
# @authors: Philippe Roy <philippe.roy@ac-grenoble.fr>
|
|
|
|
# @copyright: Copyright (C) 2023 Philippe Roy
|
|
|
|
# @license: GNU GPL
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
# UPBGE scene
|
2023-01-14 14:03:15 +01:00
|
|
|
# scene = bge.logic.getCurrentScene()
|
2023-01-14 07:49:53 +01:00
|
|
|
|
|
|
|
# Récupérer le brochage du jumeau réel
|
|
|
|
# system=importlib.import_module(scene.objects['Doc']['system']) # Système
|
|
|
|
# pin_config = system.get_pin_config()
|
|
|
|
|
|
|
|
###############################################################################
|
2023-01-14 14:03:15 +01:00
|
|
|
# Fenêtre dynamique
|
2023-01-14 07:49:53 +01:00
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
class MplCanvas(FigureCanvasQTAgg):
|
|
|
|
|
|
|
|
def __init__(self, parent=None, width=5, height=4, dpi=100):
|
|
|
|
fig = Figure(figsize=(width, height), dpi=dpi)
|
|
|
|
self.axes = fig.add_subplot(111)
|
|
|
|
super(MplCanvas, self).__init__(fig)
|
|
|
|
|
|
|
|
class MainWindow(QtWidgets.QMainWindow):
|
|
|
|
|
2023-01-14 14:03:15 +01:00
|
|
|
# Création du graphique
|
2023-01-14 07:49:53 +01:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super(MainWindow, self).__init__(*args, **kwargs)
|
2023-01-14 14:03:15 +01:00
|
|
|
self.canvas = MplCanvas(self, width=5, height=4, dpi=100)
|
|
|
|
self.setCentralWidget(self.canvas)
|
|
|
|
n_data = 50
|
|
|
|
# self.xdata = list(range(n_data))
|
|
|
|
# self.ydata = [random.randint(0, 10) for i in range(n_data)]
|
|
|
|
self.xdata = [0]
|
|
|
|
self.ydata = [0]
|
|
|
|
self.update_plot()
|
2023-01-14 07:49:53 +01:00
|
|
|
self.show()
|
|
|
|
|
2023-01-14 14:03:15 +01:00
|
|
|
# Timer pour le update_plot
|
|
|
|
self.timer = QtCore.QTimer()
|
|
|
|
self.timer.setInterval(100)
|
|
|
|
self.timer.timeout.connect(self.update_plot)
|
|
|
|
self.timer.start()
|
|
|
|
|
|
|
|
# Lecture des données et mise à jour du graphique
|
|
|
|
def update_plot(self):
|
|
|
|
|
|
|
|
# Données
|
|
|
|
# donnees = ([0,1,2,3,4], [10,1,20,3,40])
|
2023-01-15 10:05:41 +01:00
|
|
|
# print (self.xdata[len(self.xdata)-1]+1)
|
2023-01-14 14:03:15 +01:00
|
|
|
new_x=self.xdata[len(self.xdata)-1]+1
|
|
|
|
self.xdata.append(new_x)
|
|
|
|
self.ydata.append(random.randint(0, 10))
|
|
|
|
|
2023-01-15 10:05:41 +01:00
|
|
|
# Lecture du Pipe
|
|
|
|
for line in sys.stdin:
|
|
|
|
print('Output:', line.rstrip())
|
|
|
|
break
|
|
|
|
|
|
|
|
# self.ydata = self.ydata + [random.randint(0, 10)]
|
2023-01-14 14:03:15 +01:00
|
|
|
# Drop off the first y element, append a new one.
|
|
|
|
# self.ydata = self.ydata[1:] + [random.randint(0, 10)]
|
2023-01-15 10:05:41 +01:00
|
|
|
|
|
|
|
# Redraw
|
|
|
|
self.canvas.axes.cla()
|
2023-01-14 14:03:15 +01:00
|
|
|
self.canvas.axes.plot(self.xdata, self.ydata, 'r')
|
|
|
|
self.canvas.draw()
|
|
|
|
|
2023-01-14 07:49:53 +01:00
|
|
|
###############################################################################
|
2023-01-14 14:03:15 +01:00
|
|
|
# Application
|
2023-01-14 07:49:53 +01:00
|
|
|
###############################################################################
|
2023-01-15 10:05:41 +01:00
|
|
|
|
2023-01-14 14:03:15 +01:00
|
|
|
app = QtWidgets.QApplication(sys.argv)
|
|
|
|
w = MainWindow()
|
|
|
|
app.exec_()
|