Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
348 views
in Technique[技术] by (71.8m points)

python - Figure GUI freezing

I am fairly new in python, and I am trying to have a plot, based on data stored in a file. This file may be updated at any time, so I am trying to make the drawing updated every 3 seconds (so I don't use all the CPU). My problem is that the GUI freezes after the lunch.

#!/usr/bin/python
# _*_ coding: utf8 _*_

import matplotlib.pyplot as plt
import numpy as np
import time 

plt.ion()
plt.figure()
i=0
while 1:
    taille=0
    fichier=np.loadtxt('data/US.SAVE')
    fichier1=np.loadtxt('data/cond.SAVE')
    taille1=np.size(fichier1[:,1])
    taille=np.size(fichier[:,1])

    min=min(fichier[0,0],fichier1[0,0]);

    fichier[:,0]=fichier[:,0]-min
    fichier1[:,0]=fichier1[:,0]-min


    if (taille != taille1) :
        printErrors("TAILLE DE FICHIERS DIFFERENTES")


    nb_chunks=np.size(fichier1[1,:])
    nb_inputs=np.size(fichier[1,:])


    plt.subplot(3,1,1)

    plt.bar(fichier[:,0],fichier[:,1],align='center',width=0.0001, facecolor='b', label="US")
    x1,x2,y1,y2 = plt.axis()
    x1=x1-0.0001
    plt.axis([x1, x2, y1, 1.2])
    plt.legend(ncol=3,prop={'size':9})
    plt.title("US ") 
    plt.ylabel('Activation')
    plt.xlabel('Time')

    plt.subplot(3,1,2)

    plt.bar(fichier1[:,0],fichier1[:,1],align='center',width=0.0001, facecolor='b', label="response")



    plt.axis([x1, x2, y1, 1.2])
    plt.legend(ncol=3,prop={'size':9})
    plt.title("Response ") 
    plt.ylabel('Activation')
    plt.xlabel('Time')


    plt.subplot(3,1,3)

    plt.bar(fichier[:,0]-fichier1[:,0],fichier1[:,1],align='center',width=0.0001, facecolor='b', label="Error")
    plt.axis([x1, x2, y1, 1.2])
    plt.legend(ncol=3,prop={'size':9})
    plt.title("Error") 
    plt.ylabel('Activation')
    plt.xlabel('Time')
    plt.draw()
    name1='data/Conditionnement.eps'
    plt.savefig(name1,dpi=256)
    plt.draw()
    del fichier,fichier1,min
    i=i+1

    time.sleep(3)   

plt.show()

I did not find any other topic on a file based drawing.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You want to use the plt.pause(3) function instead of time.sleep(). pause includes the necessary calls to the gui main loop to cause the figure to re-draw.

also see: Python- 1 second plots continous presentation, matplotlib real-time linear line, pylab.ion() in python 2, matplotlib 1.1.1 and updating of the plot while the program runs,


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...