Multi-plots (point d'étape)

This commit is contained in:
Philippe Roy 2023-01-25 06:57:05 +01:00
parent 5243d26bd4
commit 7340621523

View File

@ -2,13 +2,14 @@ import sys
import random
import importlib
import matplotlib
import matplotlib.pyplot as plts
import csv
import xml.etree.ElementTree as ET # Creating/parsing XML file
matplotlib.use('Qt5Agg')
from PyQt5 import QtCore, QtGui, QtWidgets
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
from matplotlib.figure import Figure
import matplotlib.pyplot as plts
###############################################################################
# twin_plot_qt.py
@ -42,10 +43,8 @@ def plot_config_dict():
###############################################################################
class MplCanvas(FigureCanvasQTAgg):
def __init__(self, parent=None, width=5, height=4, dpi=100):
fig = Figure(figsize=(width, height), dpi=dpi)
self.subplot = fig.add_subplot(111)
fig, self.plt = plts.subplots(3, 1, sharex=True)
super(MplCanvas, self).__init__(fig)
###############################################################################
@ -164,7 +163,6 @@ class DynamicPlot(QtWidgets.QMainWindow):
plt.plot(self.xdata, self.ydata, 'r')
self.canvas.draw()
###############################################################################
# Graphique statique
###############################################################################
@ -176,11 +174,11 @@ class MainWindow(QtWidgets.QMainWindow):
# Zone graphique (barre d'outil et graphique)
super(MainWindow, self).__init__(*args, **kwargs)
# fig, plt = plts.subplots(3, 1, sharex=True)
# fig.subplots_adjust(hspace=0)
self.canvas = MplCanvas(self, width=5, height=4, dpi=100)
toolbar = NavigationToolbar(self.canvas, self)
# plt = self.canvas.subplot
# plt.cla()
# Implantation de la fenêtre
layout = QtWidgets.QVBoxLayout()
layout.addWidget(toolbar)
@ -222,23 +220,24 @@ class MainWindow(QtWidgets.QMainWindow):
# if plot_config[fields[i]]['group']=="0" : # Pas de groupe : nouveau plot
# plts.append(self.canvas.subplot)
plt = self.canvas.subplot
plt.cla()
# fig, plt = plts.subplots(3, 1, sharex=True)
# fig.subplots_adjust(hspace=0)
for i in range(len(fields)):
if i != 0 : # i=0 -> Ne pas afficher car c'est temps (variable t)
if twin_config[1][0].text == "True": # Configuration des plots activée
plt.plot(xdata[i], ydata[i], label=fields[i], color=plot_config[fields[i]]['color'],
self.canvas.plt[0].plot(xdata[i], ydata[i], label=fields[i], color=plot_config[fields[i]]['color'],
linewidth=plot_config[fields[i]]['linewidth'], linestyle=plot_config[fields[i]]['linestyle'], marker=plot_config[fields[i]]['marker'])
else:
plt.plot(xdata[i], ydata[i], '.-', label=fields[i])
self.canvas.plt[0].plot(xdata[i], ydata[i], '.-', label=fields[i])
# Décoration
plt.set_xlabel("Temps (s)")
plt.set_ylabel("Valeurs")
plt.set_title(sys.argv[1])
plt.axhline(linewidth=1, color='k')
plt.grid(True, linestyle='--')
plt.legend()
self.canvas.plt[0].set_xlabel("Temps (s)")
self.canvas.plt[0].set_ylabel("Valeurs")
self.canvas.plt[0].set_title(sys.argv[1])
self.canvas.plt[0].axhline(linewidth=1, color='k')
self.canvas.plt[0].grid(True, linestyle='--')
self.canvas.plt[0].legend()
# Redraw
self.canvas.draw()