Advertisement
Guest User

Untitled

a guest
Oct 26th, 2015
308
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.85 KB | None | 0 0
  1. '''
  2. a panel to display a given set of data in a wxframe as a heatmap, using pcolor
  3. from the matplotlib
  4.  
  5. @author: westermann
  6. '''
  7.  
  8. import wx
  9. import matplotlib.pyplot as plt
  10. import matplotlib.animation as animation
  11. from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas #todo: OW 26.10.15 needed?
  12.  
  13. class plotPanel(wx.Panel):
  14.     def __init__(self, parent):
  15.         wx.Panel.__init__(self, parent)
  16.         self.figure = plt.Figure()
  17.         self.subplot = self.figure.add_subplot(111)
  18.         plt.title('test')
  19.         self.canvas = FigureCanvas(self, -1, self.figure)  #ToDo: OW 26.10.15 Verstehen
  20.         self.sizer = wx.BoxSizer(wx.VERTICAL)
  21.         self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
  22.         self.SetSizer(self.sizer)
  23.         self.Fit()
  24.         self.dataSet = []
  25.         self.animator = animation.FuncAnimation(self.figure,self.anim, interval=1000)
  26.        
  27.     def anim(self, a):
  28.         if(len(self.dataSet) == 0):
  29.             return 0
  30.         i = a % len(self.dataSet)
  31.         obj = self.subplot.pcolor(self.dataSet[i], cmap='RdBu')
  32.         return obj
  33.        
  34.     def add_data(self, data):
  35.         self.dataSet.append(data)
  36.        
  37.        
  38. #
  39. #    Code for a standalone test run
  40. #
  41. class TestFrame(wx.Frame):
  42.         def __init__(self,parent,title):
  43.             wx.Frame.__init__(self,parent,title=title,size=(1000,1000))
  44.             self.statusbar = self.CreateStatusBar()
  45.             self.statusbar.SetStatusText('Status Bar')
  46.  
  47.  
  48. if __name__ == '__main__':
  49.     from numpy.random import rand #todo: OW 26.10.15 remove
  50.     app = wx.App(redirect=False)
  51.     frame = TestFrame(None, 'Debug Frame')
  52.     panel = plotPanel(frame)
  53.     frame.Show()
  54.     C = rand(10,10)
  55.     panel.add_data(C)
  56.     C = rand(10,10)
  57.     panel.add_data(C)
  58.     C = rand(10,10)
  59.     panel.add_data(C)
  60.     app.MainLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement