Bar charts and wxPyplot

From: giles@nw.com.au [mailto:giles@nw.com.au]

Is there a simple way of using wxPyPlot to draw simple
vertical bar charts ?

They are simple business charts with mostly 10 or 12 bars displayed.

There's no simple way, however:

1) you may be able to get away with plotting a bunch of square PolyMarker
objects, by careful adjustment of the size. However, I'm not sure if this
will give same result when printed;

2) seems like you could easily create a wxPyPlot.PolyBar class, e.g. (not
tested -- I just copied PolyMarker and adapted):

class PolyBar(PolyPoints):
    """Class to define marker type and style
        - All methods except __init__ are private.
    """
  
    _attributes = {'colour': 'black',
                   'width': 1,
                   'size': 2,
                   'fillcolour': None,
                   'fillstyle': wx.wxSOLID,
                   'legend': ''}

    def __init__(self, points, **attr):
        """Creates PolyMarker object
        points - sequence (array, tuple or list) of (x,y) points
        **attr - key word attributes
            Defaults:
                'colour'= 'black', - wxPen Colour any wxNamedColour
                'width'= 1, - Pen width
                'size'= 2, - Marker size
                'fillcolour'= same as colour, - wxBrush Colour any
wxNamedColour
                'fillstyle'= wx.wxSOLID, - wxBrush fill style (use
wxTRANSPARENT for no fill)
                'legend'= '' - Marker Legend to display
              
        """
      
        PolyPoints.__init__(self, points, attr)

    def draw(self, dc, printerScale, coord= None):
        colour = self.attributes['colour']
        width = self.attributes['width'] * printerScale
        size = self.attributes['size'] * printerScale
        fillcolour = self.attributes['fillcolour']
        fillstyle = self.attributes['fillstyle']

        dc.SetPen(wx.wxPen(wx.wxNamedColour(colour),int(width)))
        if fillcolour:
            dc.SetBrush(wx.wxBrush(wx.wxNamedColour(fillcolour),fillstyle))
        else:
            dc.SetBrush(wx.wxBrush(wx.wxNamedColour(colour), fillstyle))
        if coord == None:
            self._drawbar(dc, self.scaled, size)
        else:
            self._drawbar(dc, coord, size) #draw legend marker

    def getSymExtent(self, printerScale):
        """Width and Height of bar"""
        s= 5*self.attributes['size'] * printerScale
        return (s,s)

    def _drawbar(self, dc, coords, size=1):
        wh= 5.0*size
        x = coords[0] - wh
        y = coords[1]
        dc.DrawRectangle(x,y,wh,y)

Oliver