mirror of
https://forge.apps.education.fr/blender-edutech/jumeaux-numeriques.git
synced 2024-01-27 06:56:18 +01:00
Factorisation de la création des plots
This commit is contained in:
parent
dcf642df38
commit
f2e450654e
49
twin_plot.py
49
twin_plot.py
@ -26,7 +26,7 @@ def plot_config_get_enable():
|
||||
# Génère le dictionnaire plot_config à partir du fichier XML plot_config.xml
|
||||
##
|
||||
|
||||
def plot_config_get_dict():
|
||||
def plot_config_get_dict():
|
||||
plot_config_tree = ET.parse('plot_config.xml').getroot()
|
||||
plot_config_tmp={}
|
||||
for var in plot_config_tree[0][0]:
|
||||
@ -51,7 +51,7 @@ def plot_config_get(plot_config, var, key):
|
||||
# Nombre de groupe de courbe(s)
|
||||
##
|
||||
|
||||
def plot_nb(plot_config):
|
||||
def plot_nb(plot_config):
|
||||
plot_config_list=list(plot_config)
|
||||
nbgroup = 0
|
||||
|
||||
@ -78,7 +78,7 @@ def plot_nb(plot_config):
|
||||
# Fichier CSV -> Tableau X,Y
|
||||
##
|
||||
|
||||
def csv_read(file):
|
||||
def csv_read(file):
|
||||
|
||||
# Lecture fichier CSV
|
||||
fields = []
|
||||
@ -130,9 +130,9 @@ def plot_draw(plt, var, xdata, ydata, plot_config):
|
||||
linestyle=plot_config_get(plot_config, var, 'linestyle'), marker=plot_config_get(plot_config, var, 'marker'))
|
||||
|
||||
# Création des graphiques statiques
|
||||
def plots_static(canvas, fields, xdata, ydata, plot_config, title):
|
||||
def plots_static(plt, fields, xdata, ydata, plot_config, title):
|
||||
|
||||
# Configuration des plots activée
|
||||
# Configuration des plots activée
|
||||
plot_config_enable=plot_config_get_enable()
|
||||
|
||||
# Plots
|
||||
@ -172,45 +172,40 @@ def plots_static(canvas, fields, xdata, ydata, plot_config, title):
|
||||
# Création du plot unique
|
||||
if plot_nb(plot_config) ==1:
|
||||
if plot_config_enable: # Configuration des plots activée
|
||||
plot_draw(canvas.plt, var, xdata[i], ydata[i], plot_config)
|
||||
plot_draw(plt, var, xdata[i], ydata[i], plot_config)
|
||||
else:
|
||||
canvas.plt.plot(xdata[i], ydata[i], '.-', label=var) # Configuration matplotlib par défaut
|
||||
plt.plot(xdata[i], ydata[i], '.-', label=var) # Configuration matplotlib par défaut
|
||||
|
||||
# Légende ou titre d'axe y
|
||||
if plt_grp[plt_current][1]==0:
|
||||
canvas.plt.set_ylabel(var)
|
||||
plt.set_ylabel(var)
|
||||
else:
|
||||
canvas.plt.legend()
|
||||
plt.legend()
|
||||
|
||||
# Création des subplots
|
||||
if plot_nb(plot_config) >1:
|
||||
if plot_config_enable: # Configuration des plots activée
|
||||
plot_draw(canvas.plt[plt_current], var, xdata[i], ydata[i], plot_config)
|
||||
plot_draw(plt[plt_current], var, xdata[i], ydata[i], plot_config)
|
||||
else:
|
||||
canvas.plt[plt_current].plot(xdata[i], ydata[i], '.-', label=var) # Configuration matplotlib par défaut
|
||||
plt[plt_current].plot(xdata[i], ydata[i], '.-', label=var) # Configuration matplotlib par défaut
|
||||
|
||||
# Légende ou titre d'axe y
|
||||
if plt_grp[plt_current][1]==0:
|
||||
canvas.plt[plt_current].set_ylabel(var)
|
||||
plt[plt_current].set_ylabel(var)
|
||||
else:
|
||||
canvas.plt[plt_current].legend()
|
||||
plt[plt_current].legend()
|
||||
|
||||
# Décoration
|
||||
if plot_nb(plot_config) ==1: # 1 plot
|
||||
canvas.plt.set_xlabel("Temps (s)")
|
||||
canvas.plt.set_title(title)
|
||||
canvas.plt.axhline(linewidth=1, color='k')
|
||||
canvas.plt.grid(True, linestyle='--')
|
||||
plt.set_xlabel("Temps (s)")
|
||||
plt.set_title(title)
|
||||
plt.axhline(linewidth=1, color='k')
|
||||
plt.grid(True, linestyle='--')
|
||||
# canvas.plt.legend()
|
||||
else: # Plusieurs plots
|
||||
canvas.plt[plt_i-1].set_xlabel("Temps (s)")
|
||||
canvas.plt[0].set_title(title)
|
||||
plt[plt_i-1].set_xlabel("Temps (s)")
|
||||
plt[0].set_title(title)
|
||||
for i in range (plt_i):
|
||||
canvas.plt[i].axhline(linewidth=1, color='k')
|
||||
canvas.plt[i].grid(True, linestyle='--')
|
||||
# canvas.plt[i].legend()
|
||||
|
||||
# Redraw
|
||||
canvas.draw()
|
||||
|
||||
|
||||
plt[i].axhline(linewidth=1, color='k')
|
||||
plt[i].grid(True, linestyle='--')
|
||||
# plt[i].legend()
|
||||
|
@ -178,7 +178,7 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||
|
||||
# Création des graphive à partir du fichier CSV
|
||||
fields, xdata, ydata = csv_read(sys.argv[1])
|
||||
plots_static(self.canvas, fields, xdata, ydata, plot_config, sys.argv[1])
|
||||
plots_static(self.canvas.plt, fields, xdata, ydata, plot_config, sys.argv[1])
|
||||
self.show()
|
||||
|
||||
###############################################################################
|
||||
|
@ -1,5 +1,7 @@
|
||||
import sys
|
||||
from twin_plot import plot_config_get_dict, plot_config_get, plot_config_get_enable, plot_nb, csv_read, plots_static # Gestion communes des graphiques (Qt, wx)
|
||||
import csv # Creating/parsing CSV file
|
||||
import xml.etree.ElementTree as ET # Creating/parsing XML file
|
||||
from twin_plot import plot_config_get_dict, plot_config_get, plot_config_get_enable, plot_nb, csv_read, plots_static # Gestion communes des graphiques (Qt, wx)
|
||||
|
||||
import wx # GUI wxPython
|
||||
import matplotlib # Grapheur Matplotlib
|
||||
@ -23,6 +25,8 @@ plot_config={}
|
||||
###############################################################################
|
||||
|
||||
def plot_draw(plt):
|
||||
|
||||
twin_config = ET.parse('twin_config.xml').getroot()
|
||||
|
||||
# Lecture fichier CSV
|
||||
fields = []
|
||||
@ -82,10 +86,10 @@ def plot_draw(plt):
|
||||
plt_i +=1
|
||||
|
||||
# Création du plot unique
|
||||
if plot_nb() ==1:
|
||||
if plot_nb(plot_config) ==1:
|
||||
if twin_config[1][0].text == "True": # Configuration des plots activée
|
||||
plt.plot(xdata[i], ydata[i], label=var, color=plot_config_get(var, 'color'), linewidth=plot_config_get(var, 'linewidth'),
|
||||
linestyle=plot_config_get(var, 'linestyle'), marker=plot_config_get(var, 'marker'))
|
||||
plt.plot(xdata[i], ydata[i], label=var, color=plot_config_get(plot_config, var, 'color'), linewidth=plot_config_get(plot_config, var, 'linewidth'),
|
||||
linestyle=plot_config_get(plot_config, var, 'linestyle'), marker=plot_config_get(plot_config, var, 'marker'))
|
||||
else:
|
||||
plt.plot(xdata[i], ydata[i], '.-', label=var) # Configuration matplotlib par défaut
|
||||
|
||||
@ -96,10 +100,10 @@ def plot_draw(plt):
|
||||
plt.legend()
|
||||
|
||||
# Création des subplots
|
||||
if plot_nb() >1:
|
||||
if plot_nb(plot_config) >1:
|
||||
if twin_config[1][0].text == "True": # Configuration des plots activée
|
||||
plt[plt_current].plot(xdata[i], ydata[i], label=var, color=plot_config_get(var, 'color'), linewidth=plot_config_get(var, 'linewidth'),
|
||||
linestyle=plot_config_get(var, 'linestyle'), marker=plot_config_get(var, 'marker'))
|
||||
plt[plt_current].plot(xdata[i], ydata[i], label=var, color=plot_config_get(plot_config, var, 'color'), linewidth=plot_config_get(plot_config, var, 'linewidth'),
|
||||
linestyle=plot_config_get(plot_config, var, 'linestyle'), marker=plot_config_get(plot_config, var, 'marker'))
|
||||
else:
|
||||
plt[plt_current].plot(xdata[i], ydata[i], '.-', label=var) # Configuration matplotlib par défaut
|
||||
|
||||
@ -110,7 +114,7 @@ def plot_draw(plt):
|
||||
plt[plt_current].legend()
|
||||
|
||||
# Décoration
|
||||
if plot_nb() ==1: # 1 plot
|
||||
if plot_nb(plot_config) ==1: # 1 plot
|
||||
plt.set_xlabel("Temps (s)")
|
||||
# self.canvas.plt[0].set_ylabel("Valeurs")
|
||||
plt.set_title(sys.argv[1])
|
||||
@ -137,7 +141,7 @@ class CanvasFrame(wx.Frame):
|
||||
|
||||
# Création des zones graphique (Plots)
|
||||
self.figure = Figure()
|
||||
if plot_nb() ==1: # plot_nb() : nombre de graphiques
|
||||
if plot_nb(plot_config) ==1: # plot_nb() : nombre de graphiques
|
||||
plt = self.figure.subplots() # plot_nb() : nombre de graphiques
|
||||
else:
|
||||
plt = self.figure.subplots(plot_nb(plot_config), 1, sharex=True) # plot_nb() : nombre de graphiques
|
||||
@ -145,11 +149,8 @@ class CanvasFrame(wx.Frame):
|
||||
|
||||
# Création des graphive à partir du fichier CSV
|
||||
fields, xdata, ydata = csv_read(sys.argv[1])
|
||||
plots_static(self.canvas, fields, xdata, ydata, plot_config, sys.argv[1])
|
||||
self.show()
|
||||
|
||||
# # Dessin
|
||||
# plot_draw(plt)
|
||||
plots_static(plt, fields, xdata, ydata, plot_config, sys.argv[1])
|
||||
self.canvas.draw()
|
||||
|
||||
# Implantation de la fenêtre (canvas)
|
||||
self.sizer = wx.BoxSizer(wx.VERTICAL)
|
||||
|
Loading…
Reference in New Issue
Block a user