Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

matplotlib save issue

By: a guest on Jul 20th, 2012  |  syntax: Python  |  size: 1.91 KB  |  views: 40  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. import wx
  2. from matplotlib.figure import Figure
  3. from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
  4. import Image
  5.  
  6. class Test(wx.Frame):
  7.     def __init__(self):
  8.         img = Image.open('stinkbug.png')
  9.         wx.Frame.__init__(self, None, -1, 'Line save issue',size=img.size)
  10.  
  11.         self.create_menu()
  12.  
  13.         self.scroll = wx.ScrolledWindow(self, -1)
  14.         self.scroll.SetScrollbars(5,5,600,400)
  15.  
  16.         x, y = img.size
  17.         self.figure = Figure(figsize=(x/72.0, y/72.0), dpi=72)
  18.         self.canvas = FigureCanvasWxAgg(self.scroll, -1, self.figure)
  19.         self.canvas.SetBackgroundColour('grey')
  20.         self.axes = self.figure.add_axes([0.0, 0.0, 1.0, 1.0])
  21.         self.axes.set_axis_off()
  22.         self.axes.imshow(img, aspect='auto')
  23.  
  24.         self.canvas.draw()
  25.         self.background = self.canvas.copy_from_bbox(self.axes.bbox)
  26.         self.canvas.restore_region(self.background)
  27.         line, = self.axes.plot([5, 100], [5, 100], c='#00FF00',
  28.                                marker='-', zorder=1,
  29.                                animated=True)
  30.         self.axes.draw_artist(line)
  31.         self.canvas.blit(self.axes.bbox)
  32.  
  33.     def create_menu(self):
  34.         self.menubar = wx.MenuBar()
  35.        
  36.         menu_file = wx.Menu()
  37.         m_save = menu_file.Append(-1, "&Save", "Save")
  38.         self.Bind(wx.EVT_MENU, self.on_save, m_save)
  39.         menu_file.AppendSeparator()
  40.         m_exit = menu_file.Append(-1, "E&xit\tCtrl-X", "Exit")
  41.         self.Bind(wx.EVT_MENU, self.on_exit, m_exit)
  42.  
  43.         self.menubar.Append(menu_file, "&File")
  44.         self.SetMenuBar(self.menubar)
  45.  
  46.     def on_save(self, event):
  47.         self.figure.savefig(r'C:\Documents and Settings\achilds\Desktop\out.png', dpi=self.figure.dpi)
  48.  
  49.     def on_exit(self, event):
  50.         self.Destroy()
  51.  
  52. if __name__ == '__main__':
  53.     app = wx.PySimpleApp()
  54.     frame =  Test()
  55.     frame.Show()
  56.     app.MainLoop()
clone this paste RAW Paste Data