Précédent   Forum du club des développeurs et IT Pro > Autres langages > Python & Zope > Calcul scientifique
Calcul scientifique Forum d'entraide sur la programmation scientifique et bibliothèques associées (PIL, NumPy, SciPy, ...)
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse
 
Outils de la discussion
Publicité
'
Vieux 29/09/2012, 22h44   #1
nono031
Invité de passage
 
Inscription : octobre 2005
Messages : 8
Détails du profil
Informations forums :
Inscription : octobre 2005
Messages : 8
Points : 2
Points : 2
Par défaut Graphique d'évolution de températures

Bonjour à tous,

Ayant un peu de temps dans mon boulot, j'ai voulu m'essayer au Python.

Mais je reste bloqué sur un problème très bête...

J'utilise matplotlib et "gobject.timeout_add(10000, coroutine().next)" pour faire un maj toutes les 10s

Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import matplotlib.pyplot as plt
def coroutine():
    nbplot=5
    x = linspace(0, -50, nbplot+1)
 
    HK= []
 
    index=0
    HK.append(ctrl.GetHK())
 
    fig = plt.figure(1, (10., 10.))
    while(1):
        HK.append(ctrl.GetHK())
        if(index<nbplot):
            index+=1
        else:
            HK.pop(0)
        print(HK[index])
 
        fig.clear()
        fig.add_subplot(111)
        for i in range(size(HK,1)):
            plt.plot(x[:index+1], asarray(HK)[:,i], label='r' + repr(i) + ' ' + repr(HK[index][i]))
 
        plt.legend()
        plt.axis('tight')
        plt.show()
        yield True
La fonction ctrl.GetHK() retourne un tableau de 4 float

Donc la première se passe bien mais il n'y a pas de mise à jour...
Pouvez éclairer mon problème ? Car je tourne en rond, actuellement....
nono031 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/10/2012, 20h30   #2
Matthieu Brucher
Rédacteur/Modérateur
 
Avatar de Matthieu Brucher
 
Matthieu Brucher
Développeur HPC
Inscription : juillet 2005
Messages : 9 697
Détails du profil
Informations personnelles :
Nom : Matthieu Brucher
Âge : 31
Localisation : France, Pyrénées Atlantiques (Aquitaine)

Informations professionnelles :
Activité : Développeur HPC
Secteur : Industrie

Informations forums :
Inscription : juillet 2005
Messages : 9 697
Points : 18 133
Points : 18 133
:/ Je te conseille pour tout ce qui est interactif de travailler avec Traits et donc Chaco. C'est bien plus efficace à ce niveau Pour le reste, je ne connais pas trop gobject pour t'aider...
Matthieu Brucher est déconnecté   Envoyer un message privé Réponse avec citation 10
Vieux 02/10/2012, 14h41   #3
nono031
Invité de passage
 
Inscription : octobre 2005
Messages : 8
Détails du profil
Informations forums :
Inscription : octobre 2005
Messages : 8
Points : 2
Points : 2
Ok, je vais regarder ça.

Je ne pense pas que cela vienne des gobject mais plutôt de l'utilisation de la matplotlib.pyplot library

Pour faire simple, toutes les 10s, je reçois 4 float et je veux tracer l'évolution des ces 4 valeurs (4 courbes par exemple)

Merci pour ta réponse
nono031 est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 02/10/2012, 17h32   #4
nono031
Invité de passage
 
Inscription : octobre 2005
Messages : 8
Détails du profil
Informations forums :
Inscription : octobre 2005
Messages : 8
Points : 2
Points : 2
Pour ceux que cela intéresse, j'ai trouvé la solution :

créer la figure au lancement du programme puis dans ma routine
Code :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
def coroutine():
    global index, start, nbplot
    while(1):
        HK.append(ctrl.GetHK())
        if(index<nbplot):
            index+=1
            start-=1
        else:
            HK.pop(0)
        print(HK[index])
 
        fig.canvas.figure.clear()
        for i in range(4):
            fig.canvas.figure.gca().plot(x[start:nbplot+1], asarray(HK)[:,i], label='r'+repr(i)+' '+ repr(HK[index][i]))
        fig.canvas.figure.gca().grid()
        fig.canvas.figure.gca().legend(loc=2)
        fig.canvas.figure.gca().set_xlabel('time (s)')
        fig.canvas.figure.gca().set_ylabel('Temp (C)')
        fig.canvas.figure.gca().set_title('HK Camicaz')
        #fig.canvas.figure.gca().axis('tight')
        fig.canvas.draw()
 
        yield True
Je peux poster tout le code si besoin.
Pour éviter les variables globales, je vais créer un classe pour ça.
nono031 est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Cette discussion est résolue.
Outils de la discussion

Navigation rapide


Fuseau horaire GMT +2. Il est actuellement 11h12.


 
 
 
 
Partenaires

Hébergement Web