I want to use another thread for matplotlib. But when I run below script, it gives an error timer can only be started from the main thread. Any help would be appreciated.
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()
Note: Actually wxpython has its own plot library. But I couldn't succeed image read and plot data on it.