My CurrentCost desktop software is written in Python, and uses the matplotlib library for plotting graphs.
I am a big fan of matplotlib – you can create some very cool graphs with it. It’s not without it’s issues… for example, I’ve still yet to work out how to do realtime graphing with it that isn’t massively inefficient and resource intensive. But that’s for another post 🙂
One of the nice things that you get with it is a toolbar that lets the user switch between different modes that the mouse supports – zooming, panning, and so on.
Adding the toolbar is straightforward – I create an object of the class NavigationToolbar2Wx and add it to a sizer which in turn I add to the graph Plot.
self.toolbar = Toolbar(self.canvas) self.toolbar.Realize() sizer = wx.BoxSizer(wx.VERTICAL) sizer.Add(self.canvas, 1, wx.EXPAND) sizer.Add(self.toolbar, 0 , wx.LEFT | wx.EXPAND) self.SetSizer(sizer)
The NavigationToolbar2 toolbar provides a number of features but it doesn’t exactly meet my needs so last night I had a go at customising it.
I wanted to:
- remove the configure subplots button – as I don’t use subplots in my graphs
- add a couple of new buttons – for different navigation abilities
I couldn’t find this documented clearly anywhere, so thought it was worth sharing the code that I came up with.



I started the test at home this morning, when I normally start checking my emails and twitter. And it’s been running all day. While in my office, the phone was on my desk. The rest of the time it’s been in my pocket.
This post is a complete sample for creating a Firefox extension to add a button to the browser toolbar. When you click on the button, it grabs the URL from the Firefox address bar and does something with it.