Python 2.7 GUI与Matplotlib问题

时间:2016-02-01 18:37:22

标签: python python-2.7 matplotlib

我正在构建一个抬头显示的GUI,并在后台播放动画。

该工具应该从包含将要显示的信息的文本文件中读取数据。此外,动画是图像库。因此,代码每秒都会查看表中的一行,并显示该行的信息以及与该行关联的图像。

我已经使用Matplotlib实现了对这种特殊需求的可能解决方案。我的问题是,一旦代码运行,如果我点击屏幕上的任何地方,或者在循环运行时尝试打开一个新窗口,我会在程序工具栏上显示“(无响应”)状态

Figure 1 - Not Responding

如何防止此问题发生? 或者有更好的方法来实现此功能吗?我必须能够读取txt / csv文件以及一个接一个地渲染图像。

以下是代码示例:

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)

0 个答案:

没有答案