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
7340621523
commit
551760df87
@ -48,7 +48,7 @@ def commandes():
|
||||
print ("")
|
||||
|
||||
# daq(['mot_angle', 'mot_vitesse', 'portail_x', 'portail_vitesse'])
|
||||
daq(['bp_ext', 'bp_ext_r', 'bp_int', 'bp_int_r', 'fdc_o', 'fdc_o_r', 'fdc_f', 'fdc_f_r', 'mot_o', 'mot_f', 'mot_angle', 'mot_vitesse', 'portail_x', 'portail_vitesse', 'gyr', 'ir_emet', 'ir_recep', 'ir_recep_r'])
|
||||
daq(['bp_ext', 'bp_ext_r', 'bp_int', 'bp_int_r', 'fdc_o', 'fdc_o_r', 'fdc_f', 'fdc_f_r', 'mot_o', 'mot_f', 'gyr', 'mot_angle', 'mot_vitesse', 'portail_x', 'portail_vitesse', 'ir_emet', 'ir_recep', 'ir_recep_r'])
|
||||
# daq(['bp_ext', 'bp_ext_r', 'bp_int', 'bp_int_r', 'fdc_o', 'fdc_o_r', 'fdc_f', 'fdc_f_r', 'mot_o', 'mot_f', 'gyr'])
|
||||
reset_t()
|
||||
|
||||
@ -90,9 +90,9 @@ def commandes():
|
||||
# " rad - portail_vitesse : " +str(round(portail_vitesse, 3))+" mm/s - moteur_vitesse : " +str(round(mot_vitesse, 3))+
|
||||
# " rad/s - portail_pas : " +str(round(portail_pas, 3))+" mm/impulsion - moteur_pas : " +str(round(mot_pas, 3))+" rad/impulsion")
|
||||
|
||||
plot(['bp_ext', 'bp_ext_r', 'bp_int', 'bp_int_r', 'fdc_o', 'fdc_o_r', 'fdc_f', 'fdc_f_r', 'mot_o', 'mot_f', 'gyr', ['mot_angle', 'mot_vitesse', 'portail_x', 'portail_vitesse']])
|
||||
plot([['bp_ext', 'bp_ext_r'], ['bp_int', 'bp_int_r'], ['fdc_o', 'fdc_o_r'], ['fdc_f', 'fdc_f_r'], 'mot_o', 'mot_f', 'gyr', ['mot_angle', 'mot_vitesse', 'portail_x', 'portail_vitesse']])
|
||||
fin() # A garder
|
||||
|
||||
|
||||
###############################################################################
|
||||
# En: External call << DONT CHANGE THIS SECTION >>
|
||||
# Fr: Appel externe << NE PAS MODIFIER CETTE SECTION >>
|
||||
|
112
twin_plot_qt.py
112
twin_plot_qt.py
@ -30,6 +30,7 @@ plot_config={}
|
||||
# Configuration des plots
|
||||
###############################################################################
|
||||
|
||||
# Génère le dictionnaire plot_config à partir du fichier XML plot_config.xml
|
||||
def plot_config_dict():
|
||||
for var in plot_config_tree[0][0]:
|
||||
var_dict={}
|
||||
@ -38,13 +39,34 @@ def plot_config_dict():
|
||||
var_dict.update({var[i].tag : var[i].text})
|
||||
plot_config.update({var.text: var_dict})
|
||||
|
||||
# Nombre de groupe de courbe(s)
|
||||
def plot_nb():
|
||||
plot_config_list=list(plot_config)
|
||||
nbgroup = 0
|
||||
|
||||
# Regroupement ('group' > 0)
|
||||
for var in plot_config_list:
|
||||
if ('group' in plot_config[var]):
|
||||
if nbgroup < int(plot_config[var]['group']):
|
||||
nbgroup = int(plot_config[var]['group'])
|
||||
|
||||
# Plot solitaire ('group' = 0)
|
||||
# 'group' = -1 -> variable non affichée
|
||||
for var in plot_config_list:
|
||||
if ('group' in plot_config[var]):
|
||||
# print (int(plot_config[var]['group']))
|
||||
if int(plot_config[var]['group']) == 0:
|
||||
nbgroup +=1
|
||||
|
||||
return nbgroup
|
||||
|
||||
###############################################################################
|
||||
# Zone de dessin
|
||||
###############################################################################
|
||||
|
||||
class MplCanvas(FigureCanvasQTAgg):
|
||||
def __init__(self, parent=None, width=5, height=4, dpi=100):
|
||||
fig, self.plt = plts.subplots(3, 1, sharex=True)
|
||||
fig, self.plt = plts.subplots(plot_nb(), 1, sharex=True) # plot_nb() : nombre de graphiques
|
||||
super(MplCanvas, self).__init__(fig)
|
||||
|
||||
###############################################################################
|
||||
@ -172,20 +194,28 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
# Création du graphique
|
||||
def __init__(self, *args, **kwargs):
|
||||
|
||||
# Configuration des plots
|
||||
plot_config_dict()
|
||||
|
||||
# Zone graphique (barre d'outil et graphique)
|
||||
# FIXME : perd de la place quand on agrandi
|
||||
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)
|
||||
# print (self.canvas.getContentsMargins())
|
||||
toolbar = NavigationToolbar(self.canvas, self)
|
||||
# print (toolbar.getContentsMargins())
|
||||
|
||||
# Implantation de la fenêtre
|
||||
layout = QtWidgets.QVBoxLayout()
|
||||
# print (layout.getContentsMargins())
|
||||
# layout.setContentsMargins(0,0,0,0)
|
||||
layout.addWidget(toolbar)
|
||||
layout.addWidget(self.canvas)
|
||||
widget = QtWidgets.QWidget()
|
||||
# print (widget.getContentsMargins())
|
||||
widget.setLayout(layout)
|
||||
self.setCentralWidget(widget)
|
||||
# print (self.getContentsMargins())
|
||||
|
||||
# Lecture fichier CSV
|
||||
fields = []
|
||||
@ -211,33 +241,63 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
i+=1
|
||||
|
||||
# Plots
|
||||
plot_config_dict() # Configuration des plots
|
||||
# FIXME : multiplot à faire
|
||||
# plts = []
|
||||
# plt_i=0
|
||||
# for i in range(len(fields)):
|
||||
# if i != 0 or plot_config[fields[i]]['group']=="-1" : # i=0 -> Ne pas afficher car c'est temps (variable t)
|
||||
# if plot_config[fields[i]]['group']=="0" : # Pas de groupe : nouveau plot
|
||||
# plts.append(self.canvas.subplot)
|
||||
|
||||
# fig, plt = plts.subplots(3, 1, sharex=True)
|
||||
# fig.subplots_adjust(hspace=0)
|
||||
|
||||
plt_i=0 # Compteur de plot
|
||||
plt_grp=[] # Groupe de plot
|
||||
# print (plot_config)
|
||||
|
||||
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
|
||||
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:
|
||||
self.canvas.plt[0].plot(xdata[i], ydata[i], '.-', label=fields[i])
|
||||
var = fields[i]
|
||||
# print (var)
|
||||
plt_current=-1 # Numéro du plot à créer
|
||||
|
||||
if ('group' in plot_config[var]): # Pas de Plot
|
||||
if int(plot_config[var]['group']) !=-1: # Pas de Plot
|
||||
|
||||
# Plot solitaire
|
||||
if int(plot_config[var]['group']) ==0:
|
||||
plt_current = plt_i
|
||||
plt_grp.append([plt_i, 0])
|
||||
plt_i +=1
|
||||
|
||||
# Plot groupé
|
||||
else:
|
||||
plt_new = True # Flag d'un nouveau groupe
|
||||
for j in range(len(plt_grp)):
|
||||
if plt_grp[j][1] == int(plot_config[var]['group']): # Groupe déjà existant
|
||||
plt_current = plt_grp[j][1]
|
||||
plt_new = False
|
||||
break
|
||||
|
||||
# Nouveau groupe
|
||||
if plt_new:
|
||||
plt_current = plt_i
|
||||
plt_grp.append([plt_i, int(plot_config[var]['group'])])
|
||||
plt_i +=1
|
||||
|
||||
# Création du plot
|
||||
print (var, plt_current)
|
||||
if twin_config[1][0].text == "True": # Configuration des plots activée
|
||||
self.canvas.plt[plt_current].plot(xdata[i], ydata[i], label=var, color=plot_config[var]['color'],
|
||||
linewidth=plot_config[var]['linewidth'], linestyle=plot_config[var]['linestyle'], marker=plot_config[var]['marker'])
|
||||
else:
|
||||
self.canvas.plt[plt_current].plot(xdata[i], ydata[i], '.-', label=var) # Configuration matplotlib par défaut
|
||||
|
||||
# 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
|
||||
# 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:
|
||||
# self.canvas.plt[0].plot(xdata[i], ydata[i], '.-', label=fields[i])
|
||||
|
||||
# Décoration
|
||||
self.canvas.plt[0].set_xlabel("Temps (s)")
|
||||
self.canvas.plt[0].set_ylabel("Valeurs")
|
||||
self.canvas.plt[plt_i-1].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()
|
||||
for i in range (plt_i):
|
||||
self.canvas.plt[i].axhline(linewidth=1, color='k')
|
||||
self.canvas.plt[i].grid(True, linestyle='--')
|
||||
self.canvas.plt[i].legend()
|
||||
|
||||
# Redraw
|
||||
self.canvas.draw()
|
||||
|
Loading…
x
Reference in New Issue
Block a user