Python的多个数字

时间:2015-11-17 17:29:00

标签: python matplotlib

我写了这个脚本,我想用

创建不同的独立图形
Worker().start()

如果它仅在1个线程中独立工作,它在IPython中不起作用,我无法创建Worker()的多个实例。我的错是什么?

#!/usr/bin/env python
import pylab
import threading
import random

class Worker:
    def worker(self):
        samples = 100
        x_axis = pylab.arange(0,samples,1)
        y_axis = pylab.array([0]*samples)

        fig = pylab.figure(1)

        ax  = fig.add_subplot(111)
        ax.grid(True)
        ax.set_title("Realtime Plot")
        ax.set_xlabel("Time")
        ax.set_ylabel("Amplitude")
        ax.axis([0,samples,-1,1])

        line1 = ax.plot(x_axis,y_axis,'-')
        values = [0 for x in range(samples)]

        for i in range(100):
            values.append(random.random())
            nsamples = min(len(values),samples)
            x_axis = pylab.arange(len(values)-nsamples,len(values),1)
            line1[0].set_data(x_axis,pylab.array(values[-nsamples:]))
            ax.axis(
                    [x_axis.min(),
                     x_axis.max(),
                     min(pylab.array(values[-nsamples:])),
                     max(pylab.array(values[-nsamples:]))
                   ])
            pylab.draw()
            pylab.pause(0.01)       
        pylab.close()

    def start(self):
        self.t = threading.Thread(target=self.worker)
        self.t.start()

    def stop(self):
        self.t.stop

这是我得到的错误:

QPixmap: It is not safe to use pixmaps outside the GUI thread
QPixmap: It is not safe to use pixmaps outside the GUI thread
QObject::startTimer: QTimer can only be used with threads started with QThread
QObject::startTimer: QTimer can only be used with threads started with QThread
QObject::startTimer: QTimer can only be used with threads started with QThread
QObject::startTimer: QTimer can only be used with threads started with QThread
/home/canard/anaconda2/lib/python2.7/site-packages/matplotlib/backend_bases.py:2399: MatplotlibDeprecationWarning: Using default event loop until function specific to this GUI is implemented
  warnings.warn(str, mplDeprecation)
python: Fatal IO error 11 (Resource temporarily unavailable) on X server :0.

我确实尝试过使用WxAgg的Ubuntu + Anaconda和Cygwin Python 2.7。

0 个答案:

没有答案
相关问题