mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
Multi-plots (point d'étape)
This commit is contained in:
parent
5243d26bd4
commit
7340621523
@ -2,13 +2,14 @@ import sys
|
|||||||
import random
|
import random
|
||||||
import importlib
|
import importlib
|
||||||
import matplotlib
|
import matplotlib
|
||||||
|
import matplotlib.pyplot as plts
|
||||||
import csv
|
import csv
|
||||||
import xml.etree.ElementTree as ET # Creating/parsing XML file
|
import xml.etree.ElementTree as ET # Creating/parsing XML file
|
||||||
|
|
||||||
matplotlib.use('Qt5Agg')
|
matplotlib.use('Qt5Agg')
|
||||||
from PyQt5 import QtCore, QtGui, QtWidgets
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
||||||
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
|
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg, NavigationToolbar2QT as NavigationToolbar
|
||||||
from matplotlib.figure import Figure
|
import matplotlib.pyplot as plts
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# twin_plot_qt.py
|
# twin_plot_qt.py
|
||||||
@ -42,10 +43,8 @@ def plot_config_dict():
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
class MplCanvas(FigureCanvasQTAgg):
|
class MplCanvas(FigureCanvasQTAgg):
|
||||||
|
|
||||||
def __init__(self, parent=None, width=5, height=4, dpi=100):
|
def __init__(self, parent=None, width=5, height=4, dpi=100):
|
||||||
fig = Figure(figsize=(width, height), dpi=dpi)
|
fig, self.plt = plts.subplots(3, 1, sharex=True)
|
||||||
self.subplot = fig.add_subplot(111)
|
|
||||||
super(MplCanvas, self).__init__(fig)
|
super(MplCanvas, self).__init__(fig)
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -164,7 +163,6 @@ class DynamicPlot(QtWidgets.QMainWindow):
|
|||||||
plt.plot(self.xdata, self.ydata, 'r')
|
plt.plot(self.xdata, self.ydata, 'r')
|
||||||
self.canvas.draw()
|
self.canvas.draw()
|
||||||
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Graphique statique
|
# Graphique statique
|
||||||
###############################################################################
|
###############################################################################
|
||||||
@ -176,11 +174,11 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
|
|
||||||
# Zone graphique (barre d'outil et graphique)
|
# Zone graphique (barre d'outil et graphique)
|
||||||
super(MainWindow, self).__init__(*args, **kwargs)
|
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)
|
self.canvas = MplCanvas(self, width=5, height=4, dpi=100)
|
||||||
toolbar = NavigationToolbar(self.canvas, self)
|
toolbar = NavigationToolbar(self.canvas, self)
|
||||||
# plt = self.canvas.subplot
|
|
||||||
# plt.cla()
|
|
||||||
|
|
||||||
# Implantation de la fenêtre
|
# Implantation de la fenêtre
|
||||||
layout = QtWidgets.QVBoxLayout()
|
layout = QtWidgets.QVBoxLayout()
|
||||||
layout.addWidget(toolbar)
|
layout.addWidget(toolbar)
|
||||||
@ -222,23 +220,24 @@ class MainWindow(QtWidgets.QMainWindow):
|
|||||||
# if plot_config[fields[i]]['group']=="0" : # Pas de groupe : nouveau plot
|
# if plot_config[fields[i]]['group']=="0" : # Pas de groupe : nouveau plot
|
||||||
# plts.append(self.canvas.subplot)
|
# plts.append(self.canvas.subplot)
|
||||||
|
|
||||||
plt = self.canvas.subplot
|
# fig, plt = plts.subplots(3, 1, sharex=True)
|
||||||
plt.cla()
|
# fig.subplots_adjust(hspace=0)
|
||||||
|
|
||||||
for i in range(len(fields)):
|
for i in range(len(fields)):
|
||||||
if i != 0 : # i=0 -> Ne pas afficher car c'est temps (variable t)
|
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
|
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'])
|
linewidth=plot_config[fields[i]]['linewidth'], linestyle=plot_config[fields[i]]['linestyle'], marker=plot_config[fields[i]]['marker'])
|
||||||
else:
|
else:
|
||||||
plt.plot(xdata[i], ydata[i], '.-', label=fields[i])
|
self.canvas.plt[0].plot(xdata[i], ydata[i], '.-', label=fields[i])
|
||||||
|
|
||||||
# Décoration
|
# Décoration
|
||||||
plt.set_xlabel("Temps (s)")
|
self.canvas.plt[0].set_xlabel("Temps (s)")
|
||||||
plt.set_ylabel("Valeurs")
|
self.canvas.plt[0].set_ylabel("Valeurs")
|
||||||
plt.set_title(sys.argv[1])
|
self.canvas.plt[0].set_title(sys.argv[1])
|
||||||
plt.axhline(linewidth=1, color='k')
|
self.canvas.plt[0].axhline(linewidth=1, color='k')
|
||||||
plt.grid(True, linestyle='--')
|
self.canvas.plt[0].grid(True, linestyle='--')
|
||||||
plt.legend()
|
self.canvas.plt[0].legend()
|
||||||
|
|
||||||
# Redraw
|
# Redraw
|
||||||
self.canvas.draw()
|
self.canvas.draw()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user