0

Hi i'm trying to add a matplotlib chart example from the link below

Embedding a matplotlib figure inside a WxPython panel

To panel within a wxpython frame generated using WXGlade. The panel is panel_22 that needs the chart. any advice?

    #!/usr/bin/env python
 # -*- coding: CP1252 -*-
 #
 # generated by wxGlade 0.6.8 (standalone edition) on Thu Jul 31 22:23:21 2014
#

import wx

# begin wxGlade: dependencies
import gettext
# end wxGlade

# begin wxGlade: extracode
# end wxGlade


    class MyFrame1(wx.Frame):
    def __init__(self, *args, **kwds):
        # begin wxGlade: MyFrame1.__init__
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)
        self.panel_22 = wx.Panel(self, wx.ID_ANY)

        self.__set_properties()
        self.__do_layout()
        # end wxGlade

    def __set_properties(self):
        # begin wxGlade: MyFrame1.__set_properties
        self.SetTitle(_("frame_2"))
        # end wxGlade

    def __do_layout(self):
        # begin wxGlade: MyFrame1.__do_layout
        sizer_21 = wx.BoxSizer(wx.VERTICAL)
        grid_sizer_4 = wx.GridSizer(3, 3, 0, 0)
        grid_sizer_4.Add(self.panel_22, 1, wx.EXPAND, 0)
        sizer_21.Add(grid_sizer_4, 1, wx.EXPAND, 0)
        self.SetSizer(sizer_21)
        sizer_21.Fit(self)
        self.Layout()
        # end wxGlade

    # end of class MyFrame1
if __name__ == "__main__":
    gettext.install("app") # replace with the appropriate catalog name

    app =  wx.App(False)
    wx.InitAllImageHandlers()
    frame_2 = MyFrame1(None, wx.ID_ANY, "")
    app.SetTopWindow(frame_2)
    frame_2.Show()
    app.MainLoop()
Community
  • 1
  • 1

1 Answers1

0

it does not seem to matter whether it's generated in glade. so try

add two import first

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure

and then add two lines at the beginning of __do_layout:

def __do_layout(self):

    self.figure = Figure()
    self.canvas = FigureCanvas(self,panel_22, -1, self.figure)

    # begin wxGlade: MyFrame1.__do_layout
otterb
  • 2,660
  • 2
  • 29
  • 48