Here is my try at making bar graphs using the existing wxPyPlot framework
(See figure at bottom of page)
http://www.cyberus.ca/~g_will/wxPython/ScreenShots.html
IMHO it looks good and was easy to do. Bar names could be put under the bar
rather than in the legend, but it is very readable as it is. I'll leave
that to someone else as an "exercise".
The data used is
def _draw6Objects():
# Bar graph
points1=[(1,0), (1,10)]
line1 = PolyLine(points1, colour='green', legend='Feb.', width=10)
points1g=[(2,0), (2,4)]
line1g = PolyLine(points1g, colour='red', legend='Mar.', width=10)
points1b=[(3,0), (3,6)]
line1b = PolyLine(points1b, colour='blue', legend='Apr.', width=10)
points2=[(4,0), (4,12)]
line2 = PolyLine(points2, colour='Yellow', legend='May', width=10)
points2g=[(5,0), (5,8)]
line2g = PolyLine(points2g, colour='orange', legend='June',
width=10)
points2b=[(6,0), (6,4)]
line2b = PolyLine(points2b, colour='brown', legend='July', width=10)
return PlotGraphics([line1, line1g, line1b, line2, line2g, line2b],
"Bar Graph", "Months", "Number of Students")
and the drawing routine is:
def OnPlotDraw6(self, event):
#Bar Graph Example
self.resetDefaults()
self.client.SetEnableLegend(True) #turn on Legend
self.client.SetEnableGrid(True) #turn on Grid
self.client.SetXSpec('none') #turns off x-axis scale
self.client.SetYSpec('auto')
self.client.Draw(_draw6Objects(), xAxis= (0,7))
The only minor change that I made to wxPyPlot was to make the line ends
square rather than rounded. In draw method of polyline class (near line
160):
pen = wx.wxPen(wx.wxNamedColour(colour), int(width), style)
pen.SetCap(wx.wxCAP_BUTT)
dc.SetPen(pen)
Enjoy,
Gordon Williams