0

I am looking to include a Cartesian plane in my python apps GUI. Im am building the GUI using wxPython. I am wondering as to the best approach to take? The plane should be populated with images at varying locations depending on the axis.

Any help in regards to this issue would be greatly appreciated.

Regards, Dan

Daniel Flannery
  • 1,166
  • 8
  • 23
  • 51
  • Does the user need to be able to interact with the graph? – Steven Rumbalski Apr 11 '13 at 18:38
  • @StevenRumbalski Not necessarily. Having the graph refresh dynamically when the axis are changed would be a nice feature but not vital. Could you recommend approaches for both user interactive and static graphs? – Daniel Flannery Apr 11 '13 at 18:46
  • I was just thinking that you could generate the graph as an image using an [existing plotting tool](http://wiki.python.org/moin/NumericAndScientific/Plotting) such as [matplotlib](http://matplotlib.org/). – Steven Rumbalski Apr 11 '13 at 18:51
  • 1
    What do you mean by a "Cartesian plane"? Do you want axes, a grid, or just an invisible x,y coordinate system? – tom10 Apr 11 '13 at 19:12
  • Im looking for an x y axis really. I am looking to plot youtube videos in relation to their attributes. EG. and x and y axis of views, duration. – Daniel Flannery Apr 12 '13 at 13:44

1 Answers1

2

Whilst the lines aren't in exactly the right position (not sure why). You could bind to a panel and draw directly to it like so,

import wx

class Cartesian(wx.Frame):
    def __init__(self, parent=None, id=-1, title=""):
        wx.Frame.__init__(self, parent, id, title, size=(640, 480))

        self.panel = wx.Panel(self)
        self.panel.Bind(wx.EVT_PAINT, self.OnPaint)

    def OnPaint(self, event):
        dc = wx.PaintDC(event.GetEventObject())
        dc.Clear()
        dc.SetPen(wx.Pen(wx.BLACK))
        dc.DrawLine(320, 0, 320, 480)
        dc.DrawLine(0, 240, 640, 240)

app = wx.App(False)
frame = Cartesian()
frame.Show()
app.MainLoop()

So this code creates the panel to draw on based off the frame and then draws in a black pen with the dc.DrawLine() method, which takes 4 parameters, the first x/y coordinates, and the second x/y coordinates.

Alternatively you can use wx.StaticLine() in a similar fashion as such:

import wx

class Cartesian(wx.Frame):
    def __init__(self, parent=None, id=-1, title=""):
        wx.Frame.__init__(self, parent, id, title, size=(640, 480))

        self.panel = wx.Panel(self)

        wx.StaticLine(self.panel, pos=(320, 0), size=(1, 480), style=wx.LI_VERTICAL)
        wx.StaticLine(self.panel, pos=(0, 240), size=(640, 1), style=wx.LI_HORIZONTAL)

app = wx.App(False)
frame = Cartesian()
frame.Show()
app.MainLoop()
Shannon Rothe
  • 1,112
  • 5
  • 15
  • 26