COSMOS core  1.0.2 (beta)
Comprehensive Open-architecture Solution for Mission Operations Systems
plotData.GraphFrame Class Reference
Inheritance diagram for plotData.GraphFrame:
Collaboration diagram for plotData.GraphFrame:

Public Member Functions

def __init__ (self)
 
def create_menu (self)
 
def create_main_panel (self)
 
def create_status_bar (self)
 
def init_plot (self)
 
def draw_plot (self)
 
def on_pause_button (self, event)
 
def on_update_pause_button (self, event)
 
def on_cb_grid (self, event)
 
def on_cb_xlab (self, event)
 
def on_save_plot (self, event)
 
def on_redraw_timer (self, event)
 
def on_exit (self, event)
 
def flash_status_message (self, msg, flash_len_ms=1500)
 
def on_flash_status_off (self, event)
 

Public Attributes

 datagen
 
 data
 
 paused
 
 redraw_timer
 
 menubar
 
 panel
 
 canvas
 
 xmin_control
 
 xmax_control
 
 ymin_control
 
 ymax_control
 
 pause_button
 
 cb_grid
 
 cb_xlab
 
 hbox1
 
 hbox2
 
 vbox
 
 statusbar
 
 dpi
 
 fig
 
 axes
 
 plot_data
 
 timeroff
 

Static Public Attributes

string title = 'Demo: dynamic matplotlib graph'
 

Detailed Description

The main frame of the application

Constructor & Destructor Documentation

def plotData.GraphFrame.__init__ (   self)
123  def __init__(self):
124  wx.Frame.__init__(self, None, -1, self.title)
125 
126  self.datagen = DataGen()
127  self.data = [self.datagen.next()]
128  self.paused = False
129 
130  self.create_menu()
131  self.create_status_bar()
132  self.create_main_panel()
133 
134  self.redraw_timer = wx.Timer(self)
135  self.Bind(wx.EVT_TIMER, self.on_redraw_timer, self.redraw_timer)
136  self.redraw_timer.Start(100)
137 

Member Function Documentation

def plotData.GraphFrame.create_menu (   self)
138  def create_menu(self):
139  self.menubar = wx.MenuBar()
140 
141  menu_file = wx.Menu()
142  m_expt = menu_file.Append(-1, "&Save plot\tCtrl-S", "Save plot to file")
143  self.Bind(wx.EVT_MENU, self.on_save_plot, m_expt)
144  menu_file.AppendSeparator()
145  m_exit = menu_file.Append(-1, "E&xit\tCtrl-X", "Exit")
146  self.Bind(wx.EVT_MENU, self.on_exit, m_exit)
147 
148  self.menubar.Append(menu_file, "&File")
149  self.SetMenuBar(self.menubar)
150 
def plotData.GraphFrame.create_main_panel (   self)
151  def create_main_panel(self):
152  self.panel = wx.Panel(self)
153 
154  self.init_plot()
155  self.canvas = FigCanvas(self.panel, -1, self.fig)
156 
157  self.xmin_control = BoundControlBox(self.panel, -1, "X min", 0)
158  self.xmax_control = BoundControlBox(self.panel, -1, "X max", 50)
159  self.ymin_control = BoundControlBox(self.panel, -1, "Y min", 0)
160  self.ymax_control = BoundControlBox(self.panel, -1, "Y max", 100)
161 
162  self.pause_button = wx.Button(self.panel, -1, "Pause")
163  self.Bind(wx.EVT_BUTTON, self.on_pause_button, self.pause_button)
164  self.Bind(wx.EVT_UPDATE_UI, self.on_update_pause_button, self.pause_button)
165 
166  self.cb_grid = wx.CheckBox(self.panel, -1,
167  "Show Grid",
168  style=wx.ALIGN_RIGHT)
169  self.Bind(wx.EVT_CHECKBOX, self.on_cb_grid, self.cb_grid)
170  self.cb_grid.SetValue(True)
171 
172  self.cb_xlab = wx.CheckBox(self.panel, -1,
173  "Show X labels",
174  style=wx.ALIGN_RIGHT)
175  self.Bind(wx.EVT_CHECKBOX, self.on_cb_xlab, self.cb_xlab)
176  self.cb_xlab.SetValue(True)
177 
178  self.hbox1 = wx.BoxSizer(wx.HORIZONTAL)
179  self.hbox1.Add(self.pause_button, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL)
180  self.hbox1.AddSpacer(20)
181  self.hbox1.Add(self.cb_grid, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL)
182  self.hbox1.AddSpacer(10)
183  self.hbox1.Add(self.cb_xlab, border=5, flag=wx.ALL | wx.ALIGN_CENTER_VERTICAL)
184 
185  self.hbox2 = wx.BoxSizer(wx.HORIZONTAL)
186  self.hbox2.Add(self.xmin_control, border=5, flag=wx.ALL)
187  self.hbox2.Add(self.xmax_control, border=5, flag=wx.ALL)
188  self.hbox2.AddSpacer(24)
189  self.hbox2.Add(self.ymin_control, border=5, flag=wx.ALL)
190  self.hbox2.Add(self.ymax_control, border=5, flag=wx.ALL)
191 
192  self.vbox = wx.BoxSizer(wx.VERTICAL)
193  self.vbox.Add(self.canvas, 1, flag=wx.LEFT | wx.TOP | wx.GROW)
194  self.vbox.Add(self.hbox1, 0, flag=wx.ALIGN_LEFT | wx.TOP)
195  self.vbox.Add(self.hbox2, 0, flag=wx.ALIGN_LEFT | wx.TOP)
196 
197  self.panel.SetSizer(self.vbox)
198  self.vbox.Fit(self)
199 
def plotData.GraphFrame.create_status_bar (   self)
200  def create_status_bar(self):
201  self.statusbar = self.CreateStatusBar()
202 
def plotData.GraphFrame.init_plot (   self)
203  def init_plot(self):
204  self.dpi = 100
205  self.fig = Figure((3.0, 3.0), dpi=self.dpi)
206 
207  self.axes = self.fig.add_subplot(111)
208  self.axes.set_axis_bgcolor('black')
209  self.axes.set_title('Very important random data', size=12)
210 
211  pylab.setp(self.axes.get_xticklabels(), fontsize=8)
212  pylab.setp(self.axes.get_yticklabels(), fontsize=8)
213 
214  # plot the data as a line series, and save the reference
215  # to the plotted line series
216  #
217  self.plot_data = self.axes.plot(
218  self.data,
219  linewidth=1,
220  color=(1, 1, 0),
221  )[0]
222 
def plotData.GraphFrame.draw_plot (   self)
Redraws the plot
223  def draw_plot(self):
224  """ Redraws the plot
225  """
226  # when xmin is on auto, it "follows" xmax to produce a
227  # sliding window effect. therefore, xmin is assigned after
228  # xmax.
229  #
230  if self.xmax_control.is_auto():
231  xmax = len(self.data) if len(self.data) > 50 else 50
232  else:
233  xmax = int(self.xmax_control.manual_value())
234 
235  if self.xmin_control.is_auto():
236  xmin = xmax - 50
237  else:
238  xmin = int(self.xmin_control.manual_value())
239 
240  # for ymin and ymax, find the minimal and maximal values
241  # in the data set and add a mininal margin.
242  #
243  # note that it's easy to change this scheme to the
244  # minimal/maximal value in the current display, and not
245  # the whole data set.
246  #
247  if self.ymin_control.is_auto():
248  ymin = round(min(self.data), 0) - 1
249  else:
250  ymin = int(self.ymin_control.manual_value())
251 
252  if self.ymax_control.is_auto():
253  ymax = round(max(self.data), 0) + 1
254  else:
255  ymax = int(self.ymax_control.manual_value())
256 
257  self.axes.set_xbound(lower=xmin, upper=xmax)
258  self.axes.set_ybound(lower=ymin, upper=ymax)
259 
260  # anecdote: axes.grid assumes b=True if any other flag is
261  # given even if b is set to False.
262  # so just passing the flag into the first statement won't
263  # work.
264  #
265  if self.cb_grid.IsChecked():
266  self.axes.grid(True, color='gray')
267  else:
268  self.axes.grid(False)
269 
270  # Using setp here is convenient, because get_xticklabels
271  # returns a list over which one needs to explicitly
272  # iterate, and setp already handles this.
273  #
274  pylab.setp(self.axes.get_xticklabels(),
275  visible=self.cb_xlab.IsChecked())
276 
277  self.plot_data.set_xdata(np.arange(len(self.data)))
278  self.plot_data.set_ydata(np.array(self.data))
279 
280  self.canvas.draw()
281 
def plotData.GraphFrame.on_pause_button (   self,
  event 
)
282  def on_pause_button(self, event):
283  self.paused = not self.paused
284 
def plotData.GraphFrame.on_update_pause_button (   self,
  event 
)
285  def on_update_pause_button(self, event):
286  label = "Resume" if self.paused else "Pause"
287  self.pause_button.SetLabel(label)
288 
def plotData.GraphFrame.on_cb_grid (   self,
  event 
)
289  def on_cb_grid(self, event):
290  self.draw_plot()
291 
def plotData.GraphFrame.on_cb_xlab (   self,
  event 
)
292  def on_cb_xlab(self, event):
293  self.draw_plot()
294 
def plotData.GraphFrame.on_save_plot (   self,
  event 
)
295  def on_save_plot(self, event):
296  file_choices = "PNG (*.png)|*.png"
297 
298  dlg = wx.FileDialog(
299  self,
300  message="Save plot as...",
301  defaultDir=os.getcwd(),
302  defaultFile="plot.png",
303  wildcard=file_choices,
304  style=wx.SAVE)
305 
306  if dlg.ShowModal() == wx.ID_OK:
307  path = dlg.GetPath()
308  self.canvas.print_figure(path, dpi=self.dpi)
309  self.flash_status_message("Saved to %s" % path)
310 
def plotData.GraphFrame.on_redraw_timer (   self,
  event 
)
311  def on_redraw_timer(self, event):
312  # if paused do not add data, but still redraw the plot
313  # (to respond to scale modifications, grid change, etc.)
314  #
315  if not self.paused:
316  self.data.append(self.datagen.next())
317 
318  self.draw_plot()
319 
def plotData.GraphFrame.on_exit (   self,
  event 
)
320  def on_exit(self, event):
321  self.Destroy()
322 
def plotData.GraphFrame.flash_status_message (   self,
  msg,
  flash_len_ms = 1500 
)
323  def flash_status_message(self, msg, flash_len_ms=1500):
324  self.statusbar.SetStatusText(msg)
325  self.timeroff = wx.Timer(self)
326  self.Bind(
327  wx.EVT_TIMER,
328  self.on_flash_status_off,
329  self.timeroff)
330  self.timeroff.Start(flash_len_ms, oneShot=True)
331 
def plotData.GraphFrame.on_flash_status_off (   self,
  event 
)
332  def on_flash_status_off(self, event):
333  self.statusbar.SetStatusText('')
334 
335 

Member Data Documentation

string plotData.GraphFrame.title = 'Demo: dynamic matplotlib graph'
static
plotData.GraphFrame.datagen
plotData.GraphFrame.data
plotData.GraphFrame.paused
plotData.GraphFrame.redraw_timer
plotData.GraphFrame.menubar
plotData.GraphFrame.panel
plotData.GraphFrame.canvas
plotData.GraphFrame.xmin_control
plotData.GraphFrame.xmax_control
plotData.GraphFrame.ymin_control
plotData.GraphFrame.ymax_control
plotData.GraphFrame.pause_button
plotData.GraphFrame.cb_grid
plotData.GraphFrame.cb_xlab
plotData.GraphFrame.hbox1
plotData.GraphFrame.hbox2
plotData.GraphFrame.vbox
plotData.GraphFrame.statusbar
plotData.GraphFrame.dpi
plotData.GraphFrame.fig
plotData.GraphFrame.axes
plotData.GraphFrame.plot_data
plotData.GraphFrame.timeroff

The documentation for this class was generated from the following file: