Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- a panel to display a given set of data in a wxframe as a heatmap, using pcolor
- from the matplotlib
- @author: westermann
- '''
- import wx
- import matplotlib.pyplot as plt
- import matplotlib.animation as animation
- from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas #todo: OW 26.10.15 needed?
- class plotPanel(wx.Panel):
- def __init__(self, parent):
- wx.Panel.__init__(self, parent)
- self.figure = plt.Figure()
- self.subplot = self.figure.add_subplot(111)
- plt.title('test')
- self.canvas = FigureCanvas(self, -1, self.figure) #ToDo: OW 26.10.15 Verstehen
- self.sizer = wx.BoxSizer(wx.VERTICAL)
- self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
- self.SetSizer(self.sizer)
- self.Fit()
- self.dataSet = []
- self.animator = animation.FuncAnimation(self.figure,self.anim, interval=1000)
- def anim(self, a):
- if(len(self.dataSet) == 0):
- return 0
- i = a % len(self.dataSet)
- obj = self.subplot.pcolor(self.dataSet[i], cmap='RdBu')
- return obj
- def add_data(self, data):
- self.dataSet.append(data)
- #
- # Code for a standalone test run
- #
- class TestFrame(wx.Frame):
- def __init__(self,parent,title):
- wx.Frame.__init__(self,parent,title=title,size=(1000,1000))
- self.statusbar = self.CreateStatusBar()
- self.statusbar.SetStatusText('Status Bar')
- if __name__ == '__main__':
- from numpy.random import rand #todo: OW 26.10.15 remove
- app = wx.App(redirect=False)
- frame = TestFrame(None, 'Debug Frame')
- panel = plotPanel(frame)
- frame.Show()
- C = rand(10,10)
- panel.add_data(C)
- C = rand(10,10)
- panel.add_data(C)
- C = rand(10,10)
- panel.add_data(C)
- app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement