2013-09-11 4 views
1

Вот минимальный рабочий пример моего кода.Живой график с использованием matplotlib без hault

Я пытаюсь построить живой график, используя matplotlib, принимая некоторые входы от пользователя через gui. Для построения gui я использовал библиотеку easygui

Однако есть одна проблема: Граф останавливается, делая обновление от пользователя, и я хочу, чтобы он продолжался. Есть что-то, чего я здесь не хватает.

#!/usr/bin/env python 

from easygui import * 
from matplotlib.pylab import * 
import numpy 
import random 

n = 0 
fig=plt.figure() 
x=list() 
y=list() 
plt.title("live-plot generation") 
plt.xlabel('Time(s)') 
plt.ylabel('Power(mw)') 
plt.ion() 
plt.show() 
calculated=[random.random() for a in range(40)] 
recorded=[random.random() for a in range(40)] 
possible=[random.random() for a in range(5)] 

plt.axis([0,40,0,10000]) 
for a in range(0, len(recorded)): 
     temp_y= recorded[a] 
     x.append(a) 
     y.append(temp_y) 
     plt.scatter(a,temp_y) 
     plt.draw() 
     msg = "Change" 
     title = "knob" 
     choices = possible 
     if a>9: 
       b = (a/10) - numpy.fix(a/10) 
       if b==0: 
         choice = choicebox(msg, title, choices) 
         print "change:", choice 

здесь ссылка скачать easygui

sudo python setup.py install 

на основе вашей версии Linux или ОС. использовать следующие link

+0

'http://stackoverflow.com/questions/8835374/python-displaying-a-message-box-that-can-be-closed-in- the-code-no-user-interve' Благодаря этому вопросу. Моя проблема решена. – pistal

ответ

0

Благодаря J.F. Sebastian

import easygui 
from Tkinter import Tk 
from contextlib import contextmanager 

@contextmanager 
def tk(timeout=5): 
    root = Tk() # default root 
    root.withdraw() # remove from the screen 

    # destroy all widgets in `timeout` seconds 
    func_id = root.after(int(1000*timeout), root.quit) 
    try: 
     yield root 
    finally: # cleanup 
     root.after_cancel(func_id) # cancel callback 
     root.destroy() 

with tk(timeout=1.5): 
     easygui.msgbox('message') # it blocks for at most `timeout` seconds 
Смежные вопросы