navigationtoolbar: 1. force location; 2. add select button(s) only

Hi, I'm trying to add some navigation tools to my mpl embedded in a wx app.

I noticed the default navigation tools here:
and am able to implement them using this example:

However, I don't want to add the toolbar to the bottom of my canvas or to
any part of my canvas. I want to add the toolbar, or actually more
specifically, add the pan, zoom, and save buttons to a different panel and

So far I tried adding the navigation toolbar to a different sizer, which is
on a different panel, but toolbar always shows up on the canvas.

Can someone suggest some methods on how to:
1. force and add the navigation toolbar to a different sizer or panel?
2. Add select buttons from the navigation toolbar to a different sizer or
panel than where the canvas is located?

Here is my example code:


import wx
import numpy as np
import matplotlib as mpl
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg
from matplotlib.backends.backend_wx import NavigationToolbar2Wx
from matplotlib.figure import Figure

def create(parent):
    return Frame1(parent)

] = [wx.NewId() for _init_ctrls in range(3)]

class Frame1(wx.Frame):
    def _init_coll_bshPanels_Items(self, parent):
        # generated method, don't edit

        parent.AddWindow(self.panel1, 4, border=0, flag=wx.EXPAND)
        parent.AddWindow(self.panel2, 1, border=0, flag=wx.EXPAND)

    def _init_sizers(self):
        # generated method, don't edit
        self.bshPanels = wx.BoxSizer(orient=wx.HORIZONTAL)

        self.bsvPanel1 = wx.BoxSizer(orient=wx.VERTICAL)

        self.bsvPanel2 = wx.BoxSizer(orient=wx.VERTICAL)



    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(-870, 286), size=wx.Size(718, 547),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(710, 520))

        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1',
              pos=wx.Point(0, 0), size=wx.Size(568, 520),
              style=wx.RAISED_BORDER | wx.TAB_TRAVERSAL)

        self.panel2 = wx.Panel(id=wxID_FRAME1PANEL2, name='panel2',
              pos=wx.Point(568, 0), size=wx.Size(142, 520),


    def __init__(self, parent):
        self.t = np.arange(0, np.pi*2, 0.01)
        self.x = np.sin(2*np.pi*self.t)
        self.myplot =, self.x, 'b')

    def InitCanvas(self):
        self.fig = Figure(None)
        self.canvas = FigureCanvasWxAgg(self.panel1, -1, self.fig)
        self.bsvPanel1.Add(self.canvas, -1, wx.EXPAND)
## self.panel1.Fit() = self.fig.add_subplot(111)'On')
        return True

    def AddToolBar(self):
        self.toolbar = NavigationToolbar2Wx(self.canvas)
        tw, th = self.toolbar.GetSizeTuple()
        fw, fh = self.canvas.GetSizeTuple()
        self.toolbar.SetSize(wx.Size(fw, th))
        #Trying to add to different sizer than to whom the canvas belongs
        self.bsvPanel2.Add(self.toolbar, 0, wx.LEFT | wx.EXPAND)
        #but this doesn't work. The toolbar is still on the canvas,
        #but disapears as soon as I resize or do a redraw.
        #Need correct code here, please.
        return True

    def AddToolBarBtns(self):
        '''add specific tool buttons from the navigatio toolbar to panel2'''
        #need code here, if possible

if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = create(None)



Krishna Adrianto Pribadi
Test Engineer
Harley-Davidson Motor Co.
Talladega Test Facility
Vehicle Test Stands

View this message in context:
Sent from the matplotlib - users mailing list archive at