2

I am building a GUI that is a heads-up display and in the background an animation is played.

The tool is supposed to read data from a text file that contains the information that will be displayed. Also, the animation is a library of images. Thus, each second the code looks at a line in the table and displays the information for that row as well as the image associated with that row.

I have implemented a possible solution to this particular need using Matplotlib. My issue is that once the code is ran, if I click anywhere on the screen, or try to open a new window while the loop is running, I get a "(Not Responding") status on the program toolbar

Figure 1 - Not Responding

How can I prevent this issue from happening? Or are there better ways to implement this functionality? I has to be able to read a txt/csv file as well as render the images one after the other.

Here is a sample of the code:

import matplotlib.pyplot as plt
import numpy as np
import time
from scipy.misc import imread
import matplotlib.cbook as cbook
import pandas as pd
from pylab import *

#Open file with information for HUD
filename = "data.txt"
rndz_data = pd.read_table(filename, sep="\s+")

frames = np.arange(5)
plt.ion()
fig = plt.figure()

#Create array of image files
datafile = [cbook.get_sample_data('rndz0000.png'),
            cbook.get_sample_data('rndz0001.png'),
            cbook.get_sample_data('rndz0002.png'),
            cbook.get_sample_data('rndz0003.png'),
            cbook.get_sample_data('rndz0004.png')]


#Create plot and animate
for i in frames:
    img = imread(datafile[i])
    plt.clf()
    plt.imshow(img, zorder=0, extent=[0.5, 8.0, 1.0, 7.0])
    plt.plot 
    plt.draw()
    time.sleep(1)
Joe Kington
  • 275,208
  • 71
  • 604
  • 463
fonsi
  • 471
  • 8
  • 22
  • try `plt.show` instead of `plt.draw`? Here's one thread on the subject with a solution: http://stackoverflow.com/questions/28269157/plotting-in-a-non-blocking-way-with-matplotlib – Demis Feb 01 '16 at 20:02
  • When you call `time.sleep`, you're freezing the gui's mainloop as well. In this specific case, you might consider using `plt.pause(1)` instead. – Joe Kington Feb 01 '16 at 21:57
  • `plt.pause()` did the trick. Thank you so much! – fonsi Feb 02 '16 at 00:32

0 Answers0