Matplotlib in wxPython with multiple panels -


i trying turn example multi-panel example.

import os import wx import numpy np import matplotlib matplotlib.use('wxagg') import matplotlib.figure figure import matplotlib.backends.backend_wxagg wxagg   class myframe(wx.frame):     def __init__(self):         wx.frame.__init__(self, none, -1, 'title')         #self.create_menu()         self.create_main_panel()         self.draw_figure()      def create_menu(self):         self.menubar = wx.menubar()          menu_file = wx.menu()         m_exit = menu_file.append(-1, "&quit\tctrl-q", "quit")         self.bind(wx.evt_menu, self.on_exit, m_exit)         self.menubar.append(menu_file, "&file")         self.setmenubar(self.menubar)      def create_main_panel(self):         """ creates main panel controls on it:              * mpl canvas              * mpl navigation toolbar              * control panel interaction         """         self.panel = wx.panel(self)          # create mpl figure , figcanvas objects.         # 5x4 inches, 100 dots-per-inch         #         self.dpi = 100         self.fig = figure.figure((5.0, 4.0), dpi=self.dpi)         self.canvas = wxagg.figurecanvaswxagg(self.panel, -1, self.fig)         self.axes = self.fig.add_subplot(111)          # create navigation toolbar, tied canvas         #         self.toolbar = wxagg.navigationtoolbar2wxagg(self.canvas)          #         # layout box sizers         #         self.vbox = wx.boxsizer(wx.vertical)         self.vbox.add(self.canvas, 1, wx.left | wx.top | wx.grow)         #self.vbox.addspacer(25)         self.vbox.add(self.toolbar, 0, wx.expand)          self.panel.setsizer(self.vbox)         self.vbox.fit(self)      def draw_figure(self):         """ redraws figure         """         # clear axes , redraw plot anew         #         self.axes.clear()         x, y = np.random.random((10, 2)).t         self.axes.scatter(x, y)          self.canvas.draw()      def on_exit(self, event):         self.destroy()   if __name__ == '__main__':     app = wx.pysimpleapp()     app.frame = myframe()     app.frame.show()     app.mainloop() 

here have far:

import os import wx import numpy np import matplotlib matplotlib.use('wxagg') import matplotlib.figure figure import matplotlib.backends.backend_wxagg wxagg  class myframe(wx.frame):     def __init__(self, parent, id, title):     wx.frame.__init__(self, parent, id, title, size=(1000,700),style= wx.system_menu | wx.caption | wx.close_box)              self.create_main_panel()             self.draw_figure()          def create_main_panel(self):              self.hbox = wx.boxsizer(wx.horizontal)              self.left = wx.boxsizer(wx.vertical)             self.right = wx.boxsizer(wx.vertical)              self.pnl1 = wx.panel(self, -1, style=wx.simple_border)             self.pnl2 = wx.panel(self, -1, style=wx.simple_border)             self.pnl3 = wx.panel(self, -1, style=wx.simple_border)             self.pnl4 = wx.panel(self, -1, style=wx.simple_border)               self.fig = figure.figure((5.0, 4.0), dpi=100)             self.canvas = wxagg.figurecanvaswxagg(self.pnl4, -1, self.fig)             self.axes = self.fig.add_subplot(111)              self.toolbar = wxagg.navigationtoolbar2wxagg(self.canvas)              self.right.add(self.canvas, 1, wx.left | wx.top | wx.grow)             #self.right.addspacer(25)             self.right.add(self.toolbar, 0, wx.expand)              self.left.add(self.pnl1, 1, wx.expand | wx.all, 3)             self.left.add(self.pnl2, 1, wx.expand | wx.all, 3)             self.right.add(self.pnl3, 1, wx.expand | wx.all, 3)             #right.add(pnl4, 1, wx.expand | wx.all, 3)              self.hbox.add(self.left, 1, wx.expand)             self.hbox.add(self.right, 1, wx.expand)              #self.setsize((400, 120))             self.setsizer(self.hbox)             self.centre()          def draw_figure(self):              self.axes.clear()             x, y = np.random.random((10, 2)).t             self.axes.scatter(x, y)             self.canvas.draw()          def on_exit(self, event):             self.destroy()      class myapp(wx.app):         def oninit(self):             frame = myframe(none, -1, 'borders.py')             frame.show(true)             return true      app = myapp(0)     app.mainloop() 

i have tried pulling in code other examples. i've tried deeper embedding of figure sizers, dialogs, frames. seems no matter can matplotlib fig draw if thing wxpython trying do. cannot wxpython , matplotlib multiple boxes or panels @ all.

i don't have enough reputation points put pictures in first code results in : http://i.stack.imgur.com/erhul.png second gives : http://i.stack.imgur.com/6ozk2.png

first: when dealing sizing/layouting issue in example, include wx.lib.inspection module.

in line before main loop insert:

import wx.lib.inspection wxli wxli.inspectiontool().show() 

run example. when click through tree structure left ("widget tree"), panel 1 - 3 reasonable. notice, canvas , toolbar not included box sizer, , giving trouble.

    # add sizer panel 4     pnl4_sz = wx.boxsizer(wx.vertical)     # …     # add mpl stuff     pnl4_sz.add(self.canvas, 1, wx.left | wx.top | wx.grow)     assert wx.expand == wx.grow # small joke     # …     pnl4_sz.add(self.toolbar, 0, wx.expand)     self.pnl4.setsizer(pnl4_sz)      # …     # re-instate addition of pnl4     self.right.add(self.pnl4, 1, wx.expand | wx.all, 3) 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -