wxPython problem: Can't assign size of plot.PlotCanvas

Kaipo Chang@Taiwan decomposer17179 at gmail.com
Wed Apr 28 15:13:26 CEST 2010


I wrought something like
client = plot.PlotCanvas(childFrame2, 2,pos=(300,400),size=(100,200),
name=text1)
But the plotcanvas kept filling all the childFrame.
Is there a way to Really adjust the size of ploscanvas?
Thanks in advance for your help.

The problematic code is below:

class FrameWithAButton(wx.Frame):
    def __init__(self, parent, id, title, list=[]):
        wx.Frame.__init__(self, parent, id ,title, size=(500,200))
        self.data = xyList
        self.xList = []
        self.yList = []
        for (x,y) in self.data:
            self.xList.append(x)
            self.yList.append(y)
        panel = wx.Panel(self, -1)
        wx.Button(panel, 1, 'scatter', (10,10))
        wx.Button(panel, 2, 'regression line with scatter', (10,40))
        self.Bind(wx.EVT_BUTTON, self.on_scatter, id=1)
        self.Bind(wx.EVT_BUTTON, self.on_line, id=2)

    def on_scatter(self, event):
        """Plot the points in xyList.

        """
        childFrame1 = wx.Frame(self, -1, 'scatter', size=(800,600))
        client = plot.PlotCanvas(childFrame1)
        markers = plot.PolyMarker(self.data, legend='Zipf\'s law',
colour='red', size=1)
        gc = plot.PlotGraphics([markers], 'Scatter', 'logr', 'logf')
        client.Draw(gc, xAxis=(0,9), yAxis = (0,10))
        childFrame1.Show(True)

    def on_line(self, event):
        """Plot the points and draw the regression line out of xList and
            yList, inside a Plot Canvas panel;

        """
        #Succeded in making the graph, but failed to set the position of
PlotCanvas.
        #The pos=(300,400) just did not work! kaipo 2010/04/28 19:20
        (meanX, meanY, betaZero, betaOne, sumYY) = cal_beta(self.xList,
self.yList)
        childFrame2 = wx.Frame(self, -1, 'regression line with scatter',
size=(800,600))
        text1="logf = %.03f" %betaZero +" %.03f logr" %betaOne
        client = plot.PlotCanvas(childFrame2, 2,
pos=(300,400),size=(100,200), name=text1)
        regLine = plot.PolyLine([(0.0, betaZero),
((0.0-(betaZero/betaOne)), 0.0)],width=1, colour='blue')
        markers = plot.PolyMarker(self.data, legend='Zipf\'s law',
colour='red', size=1)
        gc = plot.PlotGraphics([markers, regLine], text1, 'logr', 'logf')
        client.Draw(gc, xAxis=(0,15), yAxis = (0,12))
        childFrame2.Show(True)



More information about the Python-list mailing list