From 91ffde83881287c3851dda3d61714a9c3e128385 Mon Sep 17 00:00:00 2001 From: Jean-Philippe ARGAUD Date: Wed, 29 May 2024 16:56:11 +0200 Subject: [PATCH] Observers update and documentation --- doc/en/ref_observers_requirements.rst | 302 +++++++++++++++++++++++--- doc/fr/ref_observers_requirements.rst | 302 +++++++++++++++++++++++--- src/daComposant/daCore/Templates.py | 92 ++++++-- 3 files changed, 606 insertions(+), 90 deletions(-) diff --git a/doc/en/ref_observers_requirements.rst b/doc/en/ref_observers_requirements.rst index edfd70a..12fb349 100644 --- a/doc/en/ref_observers_requirements.rst +++ b/doc/en/ref_observers_requirements.rst @@ -288,21 +288,21 @@ Print on standard output and, in the same time, save in a file of the '/tmp' dir Template **ValueGnuPlotter** ............................ -Graphically plot with Gnuplot the current value of the variable. +Graphically plot with Gnuplot the current value of the variable (persistent plot). :: import numpy, Gnuplot v=numpy.array(var[-1], ndmin=1) - global ifig, gp + global igfig, gp try: - ifig+=1 - gp('set style data lines') + igfig+=1 + gp('set title "%s (Figure %i)"'%(info,igfig)) except: - ifig=0 + igfig=0 gp=Gnuplot.Gnuplot(persist=1) + gp('set title "%s (Figure %i)"'%(info,igfig)) gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValueSerieGnuPlotter (Observer) @@ -310,21 +310,23 @@ Graphically plot with Gnuplot the current value of the variable. Template **ValueSerieGnuPlotter** ................................. -Graphically plot with Gnuplot the value series of the variable. +Graphically plot with Gnuplot the value series of the variable (persistent plot). :: import numpy, Gnuplot v=numpy.array(var[:], ndmin=1) - global ifig, gp + global igfig, gp try: - ifig+=1 - gp('set style data lines') + igfig+=1 + gp('set title "%s (Figure %i)"'%(info,igfig)) except: - ifig=0 + igfig=0 gp=Gnuplot.Gnuplot(persist=1) + gp('set title "%s (Figure %i)"'%(info,igfig)) gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) + gp('set xlabel "Step"') + gp('set ylabel "Variable"') gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValuePrinterAndGnuPlotter (Observer) @@ -332,22 +334,22 @@ Graphically plot with Gnuplot the value series of the variable. Template **ValuePrinterAndGnuPlotter** ...................................... -Print on standard output and, in the same time, graphically plot with Gnuplot the current value of the variable. +Print on standard output and, in the same time, graphically plot with Gnuplot the current value of the variable (persistent plot). :: print(str(info)+' '+str(var[-1])) import numpy, Gnuplot v=numpy.array(var[-1], ndmin=1) - global ifig,gp + global igfig, gp try: - ifig+=1 - gp('set style data lines') + igfig+=1 + gp('set title "%s (Figure %i)"'%(info,igfig)) except: - ifig=0 + igfig=0 gp=Gnuplot.Gnuplot(persist=1) + gp('set title "%s (Figure %i)"'%(info,igfig)) gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValueSeriePrinterAndGnuPlotter (Observer) @@ -355,22 +357,24 @@ Print on standard output and, in the same time, graphically plot with Gnuplot th Template **ValueSeriePrinterAndGnuPlotter** ........................................... -Print on standard output and, in the same time, graphically plot with Gnuplot the value series of the variable. +Print on standard output and, in the same time, graphically plot with Gnuplot the value series of the variable (persistent plot). :: print(str(info)+' '+str(var[:])) import numpy, Gnuplot v=numpy.array(var[:], ndmin=1) - global ifig,gp + global igfig, gp try: - ifig+=1 - gp('set style data lines') + igfig+=1 + gp('set title "%s (Figure %i)"'%(info,igfig)) except: - ifig=0 + igfig=0 gp=Gnuplot.Gnuplot(persist=1) + gp('set title "%s (Figure %i)"'%(info,igfig)) gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) + gp('set xlabel "Step"') + gp('set ylabel "Variable"') gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValuePrinterSaverAndGnuPlotter (Observer) @@ -378,7 +382,7 @@ Print on standard output and, in the same time, graphically plot with Gnuplot th Template **ValuePrinterSaverAndGnuPlotter** ........................................... -Print on standard output and, in the same, time save in a file of the '/tmp' directory and graphically plot the current value of the variable. +Print on standard output and, in the same, time save in a file of the '/tmp' directory and graphically plot the current value of the variable (persistent plot). :: @@ -395,15 +399,15 @@ Print on standard output and, in the same, time save in a file of the '/tmp' dir print('Value saved in "%s"'%f) numpy.savetxt(f,v) import Gnuplot - global ifig,gp + global igfig, gp try: - ifig+=1 - gp('set style data lines') + igfig+=1 + gp('set title "%s (Figure %i)"'%(info,igfig)) except: - ifig=0 + igfig=0 gp=Gnuplot.Gnuplot(persist=1) + gp('set title "%s (Figure %i)"'%(info,igfig)) gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValueSeriePrinterSaverAndGnuPlotter (Observer) @@ -411,7 +415,7 @@ Print on standard output and, in the same, time save in a file of the '/tmp' dir Template **ValueSeriePrinterSaverAndGnuPlotter** ................................................ -Print on standard output and, in the same, time save in a file of the '/tmp' directory and graphically plot the value series of the variable. +Print on standard output and, in the same, time save in a file of the '/tmp' directory and graphically plot the value series of the variable (persistent plot). :: @@ -428,17 +432,243 @@ Print on standard output and, in the same, time save in a file of the '/tmp' dir print('Value saved in "%s"'%f) numpy.savetxt(f,v) import Gnuplot - global ifig,gp + global igfig, gp try: - ifig+=1 - gp('set style data lines') + igfig+=1 + gp('set title "%s (Figure %i)"'%(info,igfig)) except: - ifig=0 + igfig=0 gp=Gnuplot.Gnuplot(persist=1) + gp('set title "%s (Figure %i)"'%(info,igfig)) gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) + gp('set xlabel "Step"') + gp('set ylabel "Variable"') gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) +.. index:: single: ValueMatPlotter (Observer) + +Template **ValueMatPlotter** +............................ + +Graphically plot with Matplolib the current value of the variable (non persistent plot). + +:: + + import numpy + import matplotlib.pyplot as plt + v=numpy.array(var[-1], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.plot(v) + plt.show() + +.. index:: single: ValueMatPlotterSaver (Observer) + +Template **ValueMatPlotterSaver** +................................. + +Graphically plot with Matplolib the current value of the variable, and save the figure in a file of the '/tmp' directory (persistant figure). + +:: + + import numpy, re + import matplotlib.pyplot as plt + v=numpy.array(var[-1], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.plot(v) + f='/tmp/figure_%s_%05i.pdf'%(info,imfig) + f=re.sub(r'\s','_',f) + plt.savefig(f) + plt.show() + +.. index:: single: ValueSerieMatPlotter (Observer) + +Template **ValueSerieMatPlotter** +................................. + +Graphically plot with Matplolib the value series of the variable (non persistent plot). + +:: + + import numpy + import matplotlib.pyplot as plt + v=numpy.array(var[:], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.set_xlabel('Step') + ax.set_ylabel('Variable') + ax.plot(v) + plt.show() + +.. index:: single: ValueSerieMatPlotterSaver (Observer) + +Template **ValueSerieMatPlotterSaver** +...................................... + +Graphically plot with Matplolib the value series of the variable, and save the figure in a file of the '/tmp' directory (persistant figure). + +:: + + import numpy, re + import matplotlib.pyplot as plt + v=numpy.array(var[:], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.set_xlabel('Step') + ax.set_ylabel('Variable') + ax.plot(v) + f='/tmp/figure_%s_%05i.pdf'%(info,imfig) + f=re.sub(r'\s','_',f) + plt.savefig(f) + plt.show() + +.. index:: single: ValuePrinterAndMatPlotter (Observer) + +Template **ValuePrinterAndMatPlotter** +...................................... + +Graphically plot with Matplolib the current value of the variable (non persistent plot). + +:: + + print(str(info)+' '+str(var[-1])) + import numpy + import matplotlib.pyplot as plt + v=numpy.array(var[-1], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.plot(v) + plt.show() + +.. index:: single: ValuePrinterAndMatPlotterSaver (Observer) + +Template **ValuePrinterAndMatPlotterSaver** +........................................... + +Graphically plot with Matplolib the current value of the variable, and save the figure in a file of the '/tmp' directory (persistant figure). + +:: + + print(str(info)+' '+str(var[-1])) + import numpy, re + import matplotlib.pyplot as plt + v=numpy.array(var[-1], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.plot(v) + f='/tmp/figure_%s_%05i.pdf'%(info,imfig) + f=re.sub(r'\s','_',f) + plt.savefig(f) + plt.show() + +.. index:: single: ValueSeriePrinterAndMatPlotter (Observer) + +Template **ValueSeriePrinterAndMatPlotter** +........................................... + +Graphically plot with Matplolib the value series of the variable (non persistent plot). + +:: + + print(str(info)+' '+str(var[:])) + import numpy + import matplotlib.pyplot as plt + v=numpy.array(var[:], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.set_xlabel('Step') + ax.set_ylabel('Variable') + ax.plot(v) + plt.show() + +.. index:: single: ValueSeriePrinterAndMatPlotterSaver (Observer) + +Template **ValueSeriePrinterAndMatPlotterSaver** +................................................ + +Graphically plot with Matplolib the value series of the variable, and save the figure in a file of the '/tmp' directory (persistant figure). + +:: + + print(str(info)+' '+str(var[:])) + import numpy, re + import matplotlib.pyplot as plt + v=numpy.array(var[:], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.set_xlabel('Step') + ax.set_ylabel('Variable') + ax.plot(v) + f='/tmp/figure_%s_%05i.pdf'%(info,imfig) + f=re.sub(r'\s','_',f) + plt.savefig(f) + plt.show() + .. index:: single: ValueMean (Observer) Template **ValueMean** diff --git a/doc/fr/ref_observers_requirements.rst b/doc/fr/ref_observers_requirements.rst index 377a68b..0f3e65b 100644 --- a/doc/fr/ref_observers_requirements.rst +++ b/doc/fr/ref_observers_requirements.rst @@ -300,21 +300,21 @@ Imprime sur la sortie standard et, en même temps, enregistre dans un fichier du Modèle **ValueGnuPlotter** .......................... -Affiche graphiquement avec Gnuplot la valeur courante de la variable. +Affiche graphiquement avec Gnuplot la valeur courante de la variable (affichage persistant). :: import numpy, Gnuplot v=numpy.array(var[-1], ndmin=1) - global ifig, gp + global igfig, gp try: - ifig+=1 - gp('set style data lines') + igfig+=1 + gp('set title "%s (Figure %i)"'%(info,igfig)) except: - ifig=0 + igfig=0 gp=Gnuplot.Gnuplot(persist=1) + gp('set title "%s (Figure %i)"'%(info,igfig)) gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValueSerieGnuPlotter (Observer) @@ -322,21 +322,23 @@ Affiche graphiquement avec Gnuplot la valeur courante de la variable. Modèle **ValueSerieGnuPlotter** ............................... -Affiche graphiquement avec Gnuplot la série des valeurs de la variable. +Affiche graphiquement avec Gnuplot la série des valeurs de la variable (affichage persistant). :: import numpy, Gnuplot v=numpy.array(var[:], ndmin=1) - global ifig, gp + global igfig, gp try: - ifig+=1 - gp('set style data lines') + igfig+=1 + gp('set title "%s (Figure %i)"'%(info,igfig)) except: - ifig=0 + igfig=0 gp=Gnuplot.Gnuplot(persist=1) + gp('set title "%s (Figure %i)"'%(info,igfig)) gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) + gp('set xlabel "Step"') + gp('set ylabel "Variable"') gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValuePrinterAndGnuPlotter (Observer) @@ -344,22 +346,22 @@ Affiche graphiquement avec Gnuplot la série des valeurs de la variable. Modèle **ValuePrinterAndGnuPlotter** .................................... -Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la valeur courante de la variable. +Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la valeur courante de la variable (affichage persistant). :: print(str(info)+' '+str(var[-1])) import numpy, Gnuplot v=numpy.array(var[-1], ndmin=1) - global ifig,gp + global igfig, gp try: - ifig+=1 - gp('set style data lines') + igfig+=1 + gp('set title "%s (Figure %i)"'%(info,igfig)) except: - ifig=0 + igfig=0 gp=Gnuplot.Gnuplot(persist=1) + gp('set title "%s (Figure %i)"'%(info,igfig)) gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValueSeriePrinterAndGnuPlotter (Observer) @@ -367,22 +369,24 @@ Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gn Modèle **ValueSeriePrinterAndGnuPlotter** ......................................... -Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la série des valeurs de la variable. +Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la série des valeurs de la variable (affichage persistant). :: print(str(info)+' '+str(var[:])) import numpy, Gnuplot v=numpy.array(var[:], ndmin=1) - global ifig,gp + global igfig, gp try: - ifig+=1 - gp('set style data lines') + igfig+=1 + gp('set title "%s (Figure %i)"'%(info,igfig)) except: - ifig=0 + igfig=0 gp=Gnuplot.Gnuplot(persist=1) + gp('set title "%s (Figure %i)"'%(info,igfig)) gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) + gp('set xlabel "Step"') + gp('set ylabel "Variable"') gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValuePrinterSaverAndGnuPlotter (Observer) @@ -390,7 +394,7 @@ Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gn Modèle **ValuePrinterSaverAndGnuPlotter** ......................................... -Imprime sur la sortie standard et, en même temps, enregistre dans un fichier du répertoire '/tmp' et affiche graphiquement la valeur courante de la variable. +Imprime sur la sortie standard et, en même temps, enregistre dans un fichier du répertoire '/tmp' et affiche graphiquement la valeur courante de la variable (affichage persistant). :: @@ -407,15 +411,15 @@ Imprime sur la sortie standard et, en même temps, enregistre dans un fichier du print('Value saved in "%s"'%f) numpy.savetxt(f,v) import Gnuplot - global ifig,gp + global igfig, gp try: - ifig+=1 - gp('set style data lines') + igfig+=1 + gp('set title "%s (Figure %i)"'%(info,igfig)) except: - ifig=0 + igfig=0 gp=Gnuplot.Gnuplot(persist=1) + gp('set title "%s (Figure %i)"'%(info,igfig)) gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) .. index:: single: ValueSeriePrinterSaverAndGnuPlotter (Observer) @@ -423,7 +427,7 @@ Imprime sur la sortie standard et, en même temps, enregistre dans un fichier du Modèle **ValueSeriePrinterSaverAndGnuPlotter** .............................................. -Imprime sur la sortie standard et, en même temps, enregistre dans un fichier du répertoire '/tmp' et affiche graphiquement la série des valeurs de la variable. +Imprime sur la sortie standard et, en même temps, enregistre dans un fichier du répertoire '/tmp' et affiche graphiquement la série des valeurs de la variable (affichage persistant). :: @@ -440,17 +444,243 @@ Imprime sur la sortie standard et, en même temps, enregistre dans un fichier du print('Value saved in "%s"'%f) numpy.savetxt(f,v) import Gnuplot - global ifig,gp + global igfig, gp try: - ifig+=1 - gp('set style data lines') + igfig+=1 + gp('set title "%s (Figure %i)"'%(info,igfig)) except: - ifig=0 + igfig=0 gp=Gnuplot.Gnuplot(persist=1) + gp('set title "%s (Figure %i)"'%(info,igfig)) gp('set style data lines') - gp('set title "%s (Figure %i)"'%(info,ifig)) + gp('set xlabel "Step"') + gp('set ylabel "Variable"') gp.plot( Gnuplot.Data( v, with_='lines lw 2' ) ) +.. index:: single: ValueMatPlotter (Observer) + +Modèle **ValueMatPlotter** +.......................... + +Affiche graphiquement avec Matplolib la valeur courante de la variable (affichage non persistant). + +:: + + import numpy + import matplotlib.pyplot as plt + v=numpy.array(var[-1], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.plot(v) + plt.show() + +.. index:: single: ValueMatPlotterSaver (Observer) + +Modèle **ValueMatPlotterSaver** +............................... + +Affiche graphiquement avec Matplolib la valeur courante de la variable, et enregistre la figure dans un fichier du répertoire '/tmp' (figure persistante). + +:: + + import numpy, re + import matplotlib.pyplot as plt + v=numpy.array(var[-1], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.plot(v) + f='/tmp/figure_%s_%05i.pdf'%(info,imfig) + f=re.sub(r'\s','_',f) + plt.savefig(f) + plt.show() + +.. index:: single: ValueSerieMatPlotter (Observer) + +Modèle **ValueSerieMatPlotter** +............................... + +Affiche graphiquement avec Matplolib la série des valeurs de la variable (affichage non persistant). + +:: + + import numpy + import matplotlib.pyplot as plt + v=numpy.array(var[:], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.set_xlabel('Step') + ax.set_ylabel('Variable') + ax.plot(v) + plt.show() + +.. index:: single: ValueSerieMatPlotterSaver (Observer) + +Modèle **ValueSerieMatPlotterSaver** +.................................... + +Affiche graphiquement avec Matplolib la série des valeurs de la variable, et enregistre la figure dans un fichier du répertoire '/tmp' (figure persistante). + +:: + + import numpy, re + import matplotlib.pyplot as plt + v=numpy.array(var[:], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.set_xlabel('Step') + ax.set_ylabel('Variable') + ax.plot(v) + f='/tmp/figure_%s_%05i.pdf'%(info,imfig) + f=re.sub(r'\s','_',f) + plt.savefig(f) + plt.show() + +.. index:: single: ValuePrinterAndMatPlotter (Observer) + +Modèle **ValuePrinterAndMatPlotter** +.................................... + +Affiche graphiquement avec Matplolib la valeur courante de la variable (affichage non persistant). + +:: + + print(str(info)+' '+str(var[-1])) + import numpy + import matplotlib.pyplot as plt + v=numpy.array(var[-1], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.plot(v) + plt.show() + +.. index:: single: ValuePrinterAndMatPlotterSaver (Observer) + +Modèle **ValuePrinterAndMatPlotterSaver** +......................................... + +Affiche graphiquement avec Matplolib la valeur courante de la variable, et enregistre la figure dans un fichier du répertoire '/tmp' (figure persistante). + +:: + + print(str(info)+' '+str(var[-1])) + import numpy, re + import matplotlib.pyplot as plt + v=numpy.array(var[-1], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.plot(v) + f='/tmp/figure_%s_%05i.pdf'%(info,imfig) + f=re.sub(r'\s','_',f) + plt.savefig(f) + plt.show() + +.. index:: single: ValueSeriePrinterAndMatPlotter (Observer) + +Modèle **ValueSeriePrinterAndMatPlotter** +......................................... + +Affiche graphiquement avec Matplolib la série des valeurs de la variable (affichage non persistant). + +:: + + print(str(info)+' '+str(var[:])) + import numpy + import matplotlib.pyplot as plt + v=numpy.array(var[:], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.set_xlabel('Step') + ax.set_ylabel('Variable') + ax.plot(v) + plt.show() + +.. index:: single: ValueSeriePrinterAndMatPlotterSaver (Observer) + +Modèle **ValueSeriePrinterAndMatPlotterSaver** +.............................................. + +Affiche graphiquement avec Matplolib la série des valeurs de la variable, et enregistre la figure dans un fichier du répertoire '/tmp' (figure persistante). + +:: + + print(str(info)+' '+str(var[:])) + import numpy, re + import matplotlib.pyplot as plt + v=numpy.array(var[:], ndmin=1) + global imfig, mp, ax + plt.ion() + try: + imfig+=1 + mp.suptitle('%s (Figure %i)'%(info,imfig)) + except: + imfig=0 + mp = plt.figure() + ax = mp.add_subplot(1, 1, 1) + mp.suptitle('%s (Figure %i)'%(info,imfig)) + ax.set_xlabel('Step') + ax.set_ylabel('Variable') + ax.plot(v) + f='/tmp/figure_%s_%05i.pdf'%(info,imfig) + f=re.sub(r'\s','_',f) + plt.savefig(f) + plt.show() + .. index:: single: ValueMean (Observer) Modèle **ValueMean** diff --git a/src/daComposant/daCore/Templates.py b/src/daComposant/daCore/Templates.py index 404f26d..552dcf0 100644 --- a/src/daComposant/daCore/Templates.py +++ b/src/daComposant/daCore/Templates.py @@ -149,44 +149,100 @@ ObserverTemplates.store( ) ObserverTemplates.store( name = "ValueGnuPlotter", - content = """import numpy, Gnuplot\nv=numpy.array(var[-1], ndmin=1)\nglobal ifig, gp\ntry:\n ifig+=1\n gp('set style data lines')\nexcept:\n ifig=0\n gp=Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", - fr_FR = "Affiche graphiquement avec Gnuplot la valeur courante de la variable", - en_EN = "Graphically plot with Gnuplot the current value of the variable", + content = """import numpy, Gnuplot\nv=numpy.array(var[-1], ndmin=1)\nglobal igfig, gp\ntry:\n igfig+=1\n gp('set title \"%s (Figure %i)\"'%(info,igfig))\nexcept:\n igfig=0\n gp=Gnuplot.Gnuplot(persist=1)\n gp('set title \"%s (Figure %i)\"'%(info,igfig))\n gp('set style data lines')\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", + fr_FR = "Affiche graphiquement avec Gnuplot la valeur courante de la variable (affichage persistant)", + en_EN = "Graphically plot with Gnuplot the current value of the variable (persistent plot)", order = "next", ) ObserverTemplates.store( name = "ValueSerieGnuPlotter", - content = """import numpy, Gnuplot\nv=numpy.array(var[:], ndmin=1)\nglobal ifig, gp\ntry:\n ifig+=1\n gp('set style data lines')\nexcept:\n ifig=0\n gp=Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", - fr_FR = "Affiche graphiquement avec Gnuplot la série des valeurs de la variable", - en_EN = "Graphically plot with Gnuplot the value series of the variable", + content = """import numpy, Gnuplot\nv=numpy.array(var[:], ndmin=1)\nglobal igfig, gp\ntry:\n igfig+=1\n gp('set title \"%s (Figure %i)\"'%(info,igfig))\nexcept:\n igfig=0\n gp=Gnuplot.Gnuplot(persist=1)\n gp('set title \"%s (Figure %i)\"'%(info,igfig))\n gp('set style data lines')\n gp('set xlabel \"Step\"')\n gp('set ylabel \"Variable\"')\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", + fr_FR = "Affiche graphiquement avec Gnuplot la série des valeurs de la variable (affichage persistant)", + en_EN = "Graphically plot with Gnuplot the value series of the variable (persistent plot)", order = "next", ) ObserverTemplates.store( name = "ValuePrinterAndGnuPlotter", - content = """print(str(info)+' '+str(var[-1]))\nimport numpy, Gnuplot\nv=numpy.array(var[-1], ndmin=1)\nglobal ifig,gp\ntry:\n ifig+=1\n gp('set style data lines')\nexcept:\n ifig=0\n gp=Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", - fr_FR = "Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la valeur courante de la variable", - en_EN = "Print on standard output and, in the same time, graphically plot with Gnuplot the current value of the variable", + content = """print(str(info)+' '+str(var[-1]))\nimport numpy, Gnuplot\nv=numpy.array(var[-1], ndmin=1)\nglobal igfig, gp\ntry:\n igfig+=1\n gp('set title \"%s (Figure %i)\"'%(info,igfig))\nexcept:\n igfig=0\n gp=Gnuplot.Gnuplot(persist=1)\n gp('set title \"%s (Figure %i)\"'%(info,igfig))\n gp('set style data lines')\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", + fr_FR = "Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la valeur courante de la variable (affichage persistant)", + en_EN = "Print on standard output and, in the same time, graphically plot with Gnuplot the current value of the variable (persistent plot)", order = "next", ) ObserverTemplates.store( name = "ValueSeriePrinterAndGnuPlotter", - content = """print(str(info)+' '+str(var[:]))\nimport numpy, Gnuplot\nv=numpy.array(var[:], ndmin=1)\nglobal ifig,gp\ntry:\n ifig+=1\n gp('set style data lines')\nexcept:\n ifig=0\n gp=Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", - fr_FR = "Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la série des valeurs de la variable", - en_EN = "Print on standard output and, in the same time, graphically plot with Gnuplot the value series of the variable", + content = """print(str(info)+' '+str(var[:]))\nimport numpy, Gnuplot\nv=numpy.array(var[:], ndmin=1)\nglobal igfig, gp\ntry:\n igfig+=1\n gp('set title \"%s (Figure %i)\"'%(info,igfig))\nexcept:\n igfig=0\n gp=Gnuplot.Gnuplot(persist=1)\n gp('set title \"%s (Figure %i)\"'%(info,igfig))\n gp('set style data lines')\n gp('set xlabel \"Step\"')\n gp('set ylabel \"Variable\"')\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", + fr_FR = "Imprime sur la sortie standard et, en même temps, affiche graphiquement avec Gnuplot la série des valeurs de la variable (affichage persistant)", + en_EN = "Print on standard output and, in the same time, graphically plot with Gnuplot the value series of the variable (persistent plot)", order = "next", ) ObserverTemplates.store( name = "ValuePrinterSaverAndGnuPlotter", - content = """print(str(info)+' '+str(var[-1]))\nimport numpy, re\nv=numpy.array(var[-1], ndmin=1)\nglobal istep\ntry:\n istep+=1\nexcept:\n istep=0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub(r'\\s','_',f)\nprint('Value saved in \"%s\"'%f)\nnumpy.savetxt(f,v)\nimport Gnuplot\nglobal ifig,gp\ntry:\n ifig+=1\n gp('set style data lines')\nexcept:\n ifig=0\n gp=Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", - fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier du répertoire '/tmp' et affiche graphiquement la valeur courante de la variable", - en_EN = "Print on standard output and, in the same, time save in a file of the '/tmp' directory and graphically plot the current value of the variable", + content = """print(str(info)+' '+str(var[-1]))\nimport numpy, re\nv=numpy.array(var[-1], ndmin=1)\nglobal istep\ntry:\n istep+=1\nexcept:\n istep=0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub(r'\\s','_',f)\nprint('Value saved in \"%s\"'%f)\nnumpy.savetxt(f,v)\nimport Gnuplot\nglobal igfig, gp\ntry:\n igfig+=1\n gp('set title \"%s (Figure %i)\"'%(info,igfig))\nexcept:\n igfig=0\n gp=Gnuplot.Gnuplot(persist=1)\n gp('set title \"%s (Figure %i)\"'%(info,igfig))\n gp('set style data lines')\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", + fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier du répertoire '/tmp' et affiche graphiquement la valeur courante de la variable (affichage persistant)", + en_EN = "Print on standard output and, in the same, time save in a file of the '/tmp' directory and graphically plot the current value of the variable (persistent plot)", order = "next", ) ObserverTemplates.store( name = "ValueSeriePrinterSaverAndGnuPlotter", - content = """print(str(info)+' '+str(var[:]))\nimport numpy, re\nv=numpy.array(var[:], ndmin=1)\nglobal istep\ntry:\n istep+=1\nexcept:\n istep=0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub(r'\\s','_',f)\nprint('Value saved in \"%s\"'%f)\nnumpy.savetxt(f,v)\nimport Gnuplot\nglobal ifig,gp\ntry:\n ifig+=1\n gp('set style data lines')\nexcept:\n ifig=0\n gp=Gnuplot.Gnuplot(persist=1)\n gp('set style data lines')\ngp('set title \"%s (Figure %i)\"'%(info,ifig))\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", - fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier du répertoire '/tmp' et affiche graphiquement la série des valeurs de la variable", - en_EN = "Print on standard output and, in the same, time save in a file of the '/tmp' directory and graphically plot the value series of the variable", + content = """print(str(info)+' '+str(var[:]))\nimport numpy, re\nv=numpy.array(var[:], ndmin=1)\nglobal istep\ntry:\n istep+=1\nexcept:\n istep=0\nf='/tmp/value_%s_%05i.txt'%(info,istep)\nf=re.sub(r'\\s','_',f)\nprint('Value saved in \"%s\"'%f)\nnumpy.savetxt(f,v)\nimport Gnuplot\nglobal igfig, gp\ntry:\n igfig+=1\n gp('set title \"%s (Figure %i)\"'%(info,igfig))\nexcept:\n igfig=0\n gp=Gnuplot.Gnuplot(persist=1)\n gp('set title \"%s (Figure %i)\"'%(info,igfig))\n gp('set style data lines')\n gp('set xlabel \"Step\"')\n gp('set ylabel \"Variable\"')\ngp.plot( Gnuplot.Data( v, with_='lines lw 2' ) )""", + fr_FR = "Imprime sur la sortie standard et, en même temps, enregistre dans un fichier du répertoire '/tmp' et affiche graphiquement la série des valeurs de la variable (affichage persistant)", + en_EN = "Print on standard output and, in the same, time save in a file of the '/tmp' directory and graphically plot the value series of the variable (persistent plot)", + order = "next", +) +ObserverTemplates.store( + name = "ValueMatPlotter", + content = """import numpy\nimport matplotlib.pyplot as plt\nv=numpy.array(var[-1], ndmin=1)\nglobal imfig, mp, ax\nplt.ion()\ntry:\n imfig+=1\n mp.suptitle('%s (Figure %i)'%(info,imfig))\nexcept:\n imfig=0\n mp = plt.figure()\n ax = mp.add_subplot(1, 1, 1)\n mp.suptitle('%s (Figure %i)'%(info,imfig))\nax.plot(v)\nplt.show()""", + fr_FR = "Affiche graphiquement avec Matplolib la valeur courante de la variable (affichage non persistant)", + en_EN = "Graphically plot with Matplolib the current value of the variable (non persistent plot)", + order = "next", +) +ObserverTemplates.store( + name = "ValueMatPlotterSaver", + content = """import numpy, re\nimport matplotlib.pyplot as plt\nv=numpy.array(var[-1], ndmin=1)\nglobal imfig, mp, ax\nplt.ion()\ntry:\n imfig+=1\n mp.suptitle('%s (Figure %i)'%(info,imfig))\nexcept:\n imfig=0\n mp = plt.figure()\n ax = mp.add_subplot(1, 1, 1)\n mp.suptitle('%s (Figure %i)'%(info,imfig))\nax.plot(v)\nf='/tmp/figure_%s_%05i.pdf'%(info,imfig)\nf=re.sub(r'\\s','_',f)\nplt.savefig(f)\nplt.show()""", + fr_FR = "Affiche graphiquement avec Matplolib la valeur courante de la variable, et enregistre la figure dans un fichier du répertoire '/tmp' (figure persistante)", + en_EN = "Graphically plot with Matplolib the current value of the variable, and save the figure in a file of the '/tmp' directory (persistant figure)", + order = "next", +) +ObserverTemplates.store( + name = "ValueSerieMatPlotter", + content = """import numpy\nimport matplotlib.pyplot as plt\nv=numpy.array(var[:], ndmin=1)\nglobal imfig, mp, ax\nplt.ion()\ntry:\n imfig+=1\n mp.suptitle('%s (Figure %i)'%(info,imfig))\nexcept:\n imfig=0\n mp = plt.figure()\n ax = mp.add_subplot(1, 1, 1)\n mp.suptitle('%s (Figure %i)'%(info,imfig))\n ax.set_xlabel('Step')\n ax.set_ylabel('Variable')\nax.plot(v)\nplt.show()""", + fr_FR = "Affiche graphiquement avec Matplolib la série des valeurs de la variable (affichage non persistant)", + en_EN = "Graphically plot with Matplolib the value series of the variable (non persistent plot)", + order = "next", +) +ObserverTemplates.store( + name = "ValueSerieMatPlotterSaver", + content = """import numpy, re\nimport matplotlib.pyplot as plt\nv=numpy.array(var[:], ndmin=1)\nglobal imfig, mp, ax\nplt.ion()\ntry:\n imfig+=1\n mp.suptitle('%s (Figure %i)'%(info,imfig))\nexcept:\n imfig=0\n mp = plt.figure()\n ax = mp.add_subplot(1, 1, 1)\n mp.suptitle('%s (Figure %i)'%(info,imfig))\n ax.set_xlabel('Step')\n ax.set_ylabel('Variable')\nax.plot(v)\nf='/tmp/figure_%s_%05i.pdf'%(info,imfig)\nf=re.sub(r'\\s','_',f)\nplt.savefig(f)\nplt.show()""", + fr_FR = "Affiche graphiquement avec Matplolib la série des valeurs de la variable, et enregistre la figure dans un fichier du répertoire '/tmp' (figure persistante)", + en_EN = "Graphically plot with Matplolib the value series of the variable, and save the figure in a file of the '/tmp' directory (persistant figure)", + order = "next", +) +ObserverTemplates.store( + name = "ValuePrinterAndMatPlotter", + content = """print(str(info)+' '+str(var[-1]))\nimport numpy\nimport matplotlib.pyplot as plt\nv=numpy.array(var[-1], ndmin=1)\nglobal imfig, mp, ax\nplt.ion()\ntry:\n imfig+=1\n mp.suptitle('%s (Figure %i)'%(info,imfig))\nexcept:\n imfig=0\n mp = plt.figure()\n ax = mp.add_subplot(1, 1, 1)\n mp.suptitle('%s (Figure %i)'%(info,imfig))\nax.plot(v)\nplt.show()""", + fr_FR = "Affiche graphiquement avec Matplolib la valeur courante de la variable (affichage non persistant)", + en_EN = "Graphically plot with Matplolib the current value of the variable (non persistent plot)", + order = "next", +) +ObserverTemplates.store( + name = "ValuePrinterAndMatPlotterSaver", + content = """print(str(info)+' '+str(var[-1]))\nimport numpy, re\nimport matplotlib.pyplot as plt\nv=numpy.array(var[-1], ndmin=1)\nglobal imfig, mp, ax\nplt.ion()\ntry:\n imfig+=1\n mp.suptitle('%s (Figure %i)'%(info,imfig))\nexcept:\n imfig=0\n mp = plt.figure()\n ax = mp.add_subplot(1, 1, 1)\n mp.suptitle('%s (Figure %i)'%(info,imfig))\nax.plot(v)\nf='/tmp/figure_%s_%05i.pdf'%(info,imfig)\nf=re.sub(r'\\s','_',f)\nplt.savefig(f)\nplt.show()""", + fr_FR = "Affiche graphiquement avec Matplolib la valeur courante de la variable, et enregistre la figure dans un fichier du répertoire '/tmp' (figure persistante)", + en_EN = "Graphically plot with Matplolib the current value of the variable, and save the figure in a file of the '/tmp' directory (persistant figure)", + order = "next", +) +ObserverTemplates.store( + name = "ValueSeriePrinterAndMatPlotter", + content = """print(str(info)+' '+str(var[:]))\nimport numpy\nimport matplotlib.pyplot as plt\nv=numpy.array(var[:], ndmin=1)\nglobal imfig, mp, ax\nplt.ion()\ntry:\n imfig+=1\n mp.suptitle('%s (Figure %i)'%(info,imfig))\nexcept:\n imfig=0\n mp = plt.figure()\n ax = mp.add_subplot(1, 1, 1)\n mp.suptitle('%s (Figure %i)'%(info,imfig))\n ax.set_xlabel('Step')\n ax.set_ylabel('Variable')\nax.plot(v)\nplt.show()""", + fr_FR = "Affiche graphiquement avec Matplolib la série des valeurs de la variable (affichage non persistant)", + en_EN = "Graphically plot with Matplolib the value series of the variable (non persistent plot)", + order = "next", +) +ObserverTemplates.store( + name = "ValueSeriePrinterAndMatPlotterSaver", + content = """print(str(info)+' '+str(var[:]))\nimport numpy, re\nimport matplotlib.pyplot as plt\nv=numpy.array(var[:], ndmin=1)\nglobal imfig, mp, ax\nplt.ion()\ntry:\n imfig+=1\n mp.suptitle('%s (Figure %i)'%(info,imfig))\nexcept:\n imfig=0\n mp = plt.figure()\n ax = mp.add_subplot(1, 1, 1)\n mp.suptitle('%s (Figure %i)'%(info,imfig))\n ax.set_xlabel('Step')\n ax.set_ylabel('Variable')\nax.plot(v)\nf='/tmp/figure_%s_%05i.pdf'%(info,imfig)\nf=re.sub(r'\\s','_',f)\nplt.savefig(f)\nplt.show()""", + fr_FR = "Affiche graphiquement avec Matplolib la série des valeurs de la variable, et enregistre la figure dans un fichier du répertoire '/tmp' (figure persistante)", + en_EN = "Graphically plot with Matplolib the value series of the variable, and save the figure in a file of the '/tmp' directory (persistant figure)", order = "next", ) ObserverTemplates.store( -- 2.39.2