wxPython で分割ウィンドウ内にライブ グラフを作成したい (matplotlib を使用しますか?) - これまでのところ、ロジックを処理するコードがあります: PID コントローラーを作成しています。ライブ グラフ (サンプル間の遅延を 1 秒としましょう。現時点では疑似/ランダム サンプルを使用)
私のコードはこれまでのところここにあります(以下)-アドバイスしてください
import wx
import matplotlib as mpl
mpl.use('WXAgg')
import matplotlib.pyplot as plt
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
# global constants
Kp = 10
Ki = 2
Kd = 1
# functions used
def AttentionBox( self, message ):
dialog = wx.MessageDialog(self, message, 'Attention!', wx.ICON_ERROR)
dialog.ShowModal()
dialog.Destroy()
def StatusBar( self, message=None):
statusMessage = "PID constants( " + str(Kp)+","+str(Ki)+","+str(Kd)+" ): "
self.statusbar.SetStatusText( statusMessage + message )
class PIDFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title="PID Flow Controller", size=(1000,550))
# split the screen
self.sp = wx.SplitterWindow(self)
self.p1 = wx.Panel(self.sp, style = wx.SUNKEN_BORDER)
self.p2 = wx.Panel(self.sp, style = wx.SUNKEN_BORDER)
self.sp.SplitVertically(self.p1, self.p2, 860)
self.statusbar = self.CreateStatusBar()
StatusBar(self, "System Idle")
# define Temperature and Flow Control
wx.StaticBox(self.p2, -1, "System Control", pos=(5, 5), size=(100, 240))
wx.StaticText(self.p2, -1,"Target (litres/min):", pos=(15, 100))
self.Heater = wx.CheckBox(self.p2, -1 , "Heater", pos=(20,35))
self.Chiller = wx.CheckBox(self.p2, -1 , "Chiller", pos=(20,65))
self.TargetFlow = wx.SpinCtrl(self.p2, -1, "100", pos=(15,120), size=(80, 20), min=0, max=350)
self.ActivateButton = wx.Button(self.p2, -1, "Activate",pos=(20,180))
self.ActivateButton.Bind(wx.EVT_BUTTON, self.ActivateSystem)
self.StopButton = wx.Button(self.p2, -1, "Stop", pos=(20,215))
self.StopButton.Bind(wx.EVT_BUTTON, self.StopSystem)
############################################ BUTTONS ######################################################
def ActivateSystem(self, event):
if( self.Heater.GetValue() and self.Chiller.GetValue() ):
StatusBar(self,"Target Flow: " + str(self.TargetFlow.GetValue()) + " litres/min" )
self.Heater.SetValue(0)
self.Chiller.SetValue(0)
AttentionBox( self, "Heater and Chiller? Not Possible - Neither Activated" )
elif( self.Heater.GetValue() ):
StatusBar(self,"Heater Active. Target Flow: " + str(self.TargetFlow.GetValue()) + " litres/min" )
elif( self.Chiller.GetValue() ):
StatusBar(self,"Chiller Active. Target Flow: " + str(self.TargetFlow.GetValue()) + " litres/min" )
else:
StatusBar(self,"Target Flow: " + str(self.TargetFlow.GetValue()) + " litres/min" )
def StopSystem(self, event):
StatusBar(self, "System Idle" )
self.Heater.SetValue(0)
self.Chiller.SetValue(0)
self.TargetFlow.SetValue(0)
############################################ GRAPHING ######################################################
app = wx.App(redirect=False)
frame = PIDFrame(None, -1)
frame.Show()
app.MainLoop()