【发布时间】:2019-05-16 11:32:43
【问题描述】:
我想为 matplotlib 使用另一个线程。但是当我在脚本下面运行时,它给出了一个错误定时器只能从主线程启动。 任何帮助将不胜感激。
import wx
from threading import Thread
import serial
import threading
import time
import matplotlib.pyplot as plt
import matplotlib.animation as animation
fig, ax1 = plt.subplots( )
def runA():
print("THREAD")
while True:
def mix(i)
x=[1,3,5]
y=[13,5,23]
plt.plot(x,y)
time.sleep(1)
ani =animation. FuncAnimation(fig,mix)
plt.show()
class MyFrame1 ( wx.Frame ):
def __init__ (self, parent):
wx.Frame.__init__(self, parent)
self.SetSizeHints( wx.Defaultsize, wx.DefaultSize)
bSizer3= wx.BoxSizer(wx.VERTICAL)
self.button1= wx.Button( self, wx.ID_ANY, "mybutton1", wx.DefaultPosition, wx.DefaultSize, 0)
bsizer3.Add( self.button1, 1, wx.ALL|wx.EXPAND, 5)
self.button2= wx.Button( self, wx.ID_ANY, "mybutton2", wx.DefaultPosition, wx.DefaultSize, 0)
bsizer3.Add( self.button2, 1, wx.ALL|wx.EXPAND, 5)
self SetSizer( bsizer3)
self.Layout ()
self.Centre( wx. BOTH )
# Connect Events
self.button1.Bind(wx.EVT_BUTTON, self.b1_f )
self.button2.Bind(wx.EVT_BUTTON, self.b2_f )
def b1_f( self, event ):
t2=Thread (target =runA)
t2.start()
def b2_f( self, event):
print("heLLo")
if __name__ == "__main__":
app = wx.App(False)
frame=MyFrame1 (None)
frame.Show(True)
app.MainLoop()
注意:实际上 wxpython 有自己的绘图库。但我无法成功读取图像并在其上绘制数据。
【问题讨论】:
标签: python multithreading matplotlib wxpython