how to draw a plot without data using wxplot?

Hi, all

I'm play with wxplot lately. But I need to draw a plot only with
axises and labels, no data, and try following code without success. I
just wonder if it is possible to draw a plot without any data?Because
I want to draw the data later.Could anybody tell me how to do it?Any
help would be appreciated!

···

#===========================================

import wx
import wx.lib.plot as plotlib

class myFrame(wx.Frame): ## {{{
    def __init__(self, *args, **kwds):
        wx.Frame.__init__(self, *args, **kwds)
        ##------ your widgets
        self.canvas_ = plotlib.PlotCanvas(self)
        self.draw()
        ##------ put stuff into sizer
        self.sizer_ = wx.BoxSizer(wx.VERTICAL)
        self.sizer_.Add(self.canvas_, proportion = 1, flag = wx.EXPAND)

        ## apply sizer
        self.SetSizer(self.sizer_)
        self.SetAutoLayout(True)
    def draw(self):
        self.canvas_.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
        self.canvas_.SetFontSizeAxis(10)
        self.canvas_.SetFontSizeLegend(7)
        self.canvas_.SetXSpec('auto')
        self.canvas_.SetYSpec('auto')
        # data = [(0, 25.1), (1, 30), (2, 40), (3, 50), (4, 25.1), (5,
30), (6, 40), (7, 50)]
        # marker = plotlib.PolyMarker(data, legend='', colour='green',
marker='cross',size=1)
        # lines = plotlib.PolyLine(data, legend= 'Red Line', colour='red')
        # gph = plotlib.PlotGraphics([lines, marker],"Graph Title", "X
Axis", "Y Axis")
        gph = plotlib.PlotGraphics([],"Graph Title", "X Axis", "Y Axis")
        self.canvas_.Draw(gph, (0, 30), (-10, 40))
## }}}

def main(): ## {{{
    app = wx.PySimpleApp(0)
    frame = myFrame(None, -1, title = '')
    frame.Show(True)
    app.SetTopWindow(frame)
    app.MainLoop()
## }}}

if __name__ == "__main__":main()

Bruce Who <bruce.who.hk <at> gmail.com> writes:

Hi, all

I'm play with wxplot lately. But I need to draw a plot only with
axises and labels, no data, and try following code without success. I
just wonder if it is possible to draw a plot without any data?Because
I want to draw the data later.Could anybody tell me how to do it?Any
help would be appreciated!

I achieved that by subclassing PlotGraphics and overriding the boundingBox
method:

class Graphics(PlotGraphics):
    def __init__(self, *args, **kwargs):
        PlotGraphics.__init__(self,*args,**kwargs)

    def boundingBox(self):
        if len(self.objects) == 0:
            return _Numeric.array([-1.0,-1.0]),_Numeric.array([1.0,1.0])
        p1, p2 = self.objects[0].boundingBox()
        for o in self.objects[1:]:
            p1o, p2o = o.boundingBox()
            p1 = _Numeric.minimum(p1, p1o)
            p2 = _Numeric.maximum(p2, p2o)
        return p1, p2

When you pass an empty list when creating a new Graphics instance an empty
plot wil be drawn.

Christian

Hi, Christian

I got another way to do it which is simple and stupid: when you want
to draw an empty plot, just plot a marker outside the plot:

            marker = plotlib.PolyMarker([(-1,-1)])
            gph = plotlib.PlotGraphics([marker], sectionName, "", "")
            self.canvas_.Draw(gph, (0, 50), (-10, 40))

the marker (-1,-1) can never be seen because it's out of the plot
(0,50), (-10,40).

···

On 8/13/06, Christian Kristukat <ckkart@hoc.net> wrote:

I achieved that by subclassing PlotGraphics and overriding the boundingBox
method:

class Graphics(PlotGraphics):
   def __init__(self, *args, **kwargs):
       PlotGraphics.__init__(self,*args,**kwargs)

   def boundingBox(self):
       if len(self.objects) == 0:
           return _Numeric.array([-1.0,-1.0]),_Numeric.array([1.0,1.0])
       p1, p2 = self.objects[0].boundingBox()
       for o in self.objects[1:]:
           p1o, p2o = o.boundingBox()
           p1 = _Numeric.minimum(p1, p1o)
           p2 = _Numeric.maximum(p2, p2o)
       return p1, p2

When you pass an empty list when creating a new Graphics instance an empty
plot wil be drawn.

Christian

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

I just hope that the author of wxplot add Christian's code to wxplot.

···

On 8/13/06, Christian Kristukat <ckkart@hoc.net> wrote:

I achieved that by subclassing PlotGraphics and overriding the boundingBox
method:

class Graphics(PlotGraphics):
   def __init__(self, *args, **kwargs):
       PlotGraphics.__init__(self,*args,**kwargs)

   def boundingBox(self):
       if len(self.objects) == 0:
           return _Numeric.array([-1.0,-1.0]),_Numeric.array([1.0,1.0])
       p1, p2 = self.objects[0].boundingBox()
       for o in self.objects[1:]:
           p1o, p2o = o.boundingBox()
           p1 = _Numeric.minimum(p1, p1o)
           p2 = _Numeric.maximum(p2, p2o)
       return p1, p2

When you pass an empty list when creating a new Graphics instance an empty
plot wil be drawn.

Christian

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org