1

我正在wx用 python 编写我的第一个应用程序作为绘图的前端matplotlib。我成功地将我的数据放入numpy数组anglescol_cnts. 但是,当我发出 plt.plot 我收到以下错误

usr/lib64/python2.6/site-packages/matplotlib/backends/backend_gtk.py:621: DeprecationWarning: Use the new widget gtk.Tooltip Segmentation fault (core dumped)

我的代码已附加。我不知道从哪里开始调试。我已将其追踪到 plt.plot 行,但在没有进一步信息的情况下,我迷路了。我正在python 2.6运行rhel 6.4

#!/usr/bin/env python

import wx
from wx.lib.masked import NumCtrl
import matplotlib.pyplot as plt
import numpy as np
import pylab
from datetime import datetime
import time

class NeoProbe(wx.Frame):

    def __init__(self, parent, title):
        super(NeoProbe, self).__init__(parent, title=title, 
            size=(750, 400))

        self.probe_list = ['Old','New']
        #default probe is old
        self.default_probe = self.probe_list[0]

        self.InitUI()
        self.Centre()
        self.Show()



    def InitUI(self):

        panel = wx.Panel(self)

        font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT)
        font.SetPointSize(9)

        vbox = wx.BoxSizer(wx.VERTICAL)

        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        st1 = wx.StaticText(panel, label='Date')
        st1.SetFont(font)
        hbox1.Add(st1, flag=wx.RIGHT, border=8)
        self.dp = wx.DatePickerCtrl(panel,wx.ID_ANY,wx.DefaultDateTime,wx.DefaultPosition)
        self.dp.SetFont(font)
        hbox1.Add(self.dp,flag=wx.RIGHT,border=10)
        hbox1.Add((80,1))
        st2 = wx.StaticText(panel, label='Probe')
        st2.SetFont(font)
        hbox1.Add(st2, flag=wx.RIGHT, border=8)

        cb1 = wx.ComboBox(panel,wx.ID_ANY,choices = self.probe_list,
                          value=self.default_probe,
                          style=wx.TE_PROCESS_ENTER,size=(100, 30))
        cb1.SetFont(font)
        hbox1.Add(cb1,proportion=0,flag=wx.ALIGN_RIGHT|wx.LEFT, border =10)
        vbox.Add(hbox1, flag=wx.LEFT|wx.RIGHT|wx.TOP, border=10)

        vbox.Add((-1, 10))

        ## Now add grid sizer
        fgs = wx.FlexGridSizer(10,6,9,25)
        bfont = wx.Font(10,wx.DEFAULT,wx.NORMAL,wx.BOLD)
        angle = wx.StaticText(panel,label="Angle")
        angle.SetFont(bfont)
        count_c = wx.StaticText(panel,label="Counts (C)")
        count_c.SetFont(bfont)
        count_u = wx.StaticText(panel,label="Counts (U)")
        count_u.SetFont(bfont)
        angle2 = wx.StaticText(panel,label="Angle")
        angle2.SetFont(bfont)
        count_c2 = wx.StaticText(panel,label="Counts (C)")
        count_c2.SetFont(bfont)
        count_u2 = wx.StaticText(panel,label="Counts (U)")
        count_u2.SetFont(bfont)

        #Set input boxes for results
        self.numctrl_ccm90 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucm90 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccp90 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucp90 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccm75 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucm75 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccp75 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucp75 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccm60 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucm60 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccp60 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucp60 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccm45 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucm45 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccp45 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucp45 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccm30 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucm30 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccp30 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucp30 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccm15 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucm15 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccp15 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucp15 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_cc0 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_uc0 = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_fwhm = NumCtrl(panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)

        fgs.AddMany([(angle),(count_c), (count_u),(angle2),(count_c2), (count_u2),
                     (wx.StaticText(panel, -1, '-90')),
                     (self.numctrl_ccm90,0,wx.EXPAND,5),
                     (self.numctrl_ucm90,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '90')),
                     (self.numctrl_ccp90,0,wx.EXPAND,5),
                     (self.numctrl_ucp90,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '-75')),
                     (self.numctrl_ccm75,0,wx.EXPAND,5),
                     (self.numctrl_ucm75,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '75')),
                     (self.numctrl_ccp75,0,wx.EXPAND,5),
                     (self.numctrl_ucp75,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '-60')),
                     (self.numctrl_ccm60,0,wx.EXPAND,5),
                     (self.numctrl_ucm60,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '60')),
                     (self.numctrl_ccp60,0,wx.EXPAND,5),
                     (self.numctrl_ucp60,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '-45')),
                     (self.numctrl_ccm45,0,wx.EXPAND,5),
                     (self.numctrl_ucm45,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '45')),
                     (self.numctrl_ccp45,0,wx.EXPAND,5),
                     (self.numctrl_ucp45,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '-30')),
                     (self.numctrl_ccm30,0,wx.EXPAND,5),
                     (self.numctrl_ucm30,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '30')),
                     (self.numctrl_ccp30,0,wx.EXPAND,5),
                     (self.numctrl_ucp30,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '-15')),
                     (self.numctrl_ccm15,0,wx.EXPAND,5),
                     (self.numctrl_ucm15,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '15')),
                     (self.numctrl_ccp15,0,wx.EXPAND,5),
                     (self.numctrl_ucp15,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '0')),
                     (self.numctrl_cc0,0,wx.EXPAND,5),
                     (self.numctrl_uc0,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, '')),
                     (wx.StaticText(panel, -1, '')),
                     (wx.StaticText(panel, -1, '')),
                     (wx.StaticText(panel, -1, '')),
                     (wx.StaticText(panel, -1, '')),
                     (wx.StaticText(panel, -1, '')),
                     (wx.StaticText(panel, -1, 'FWHM')),
                     (self.numctrl_fwhm,0,wx.EXPAND,5),
                     (wx.StaticText(panel, -1, 'deg'))])


        vbox.Add(fgs, proportion=1,flag = wx.LEFT | wx.RIGHT |wx.ALIGN_CENTER,border=5)

        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        graph_btn = wx.Button(panel, label='Plot', size=(70, 30))
        hbox2.Add(graph_btn)
        db_btn = wx.Button(panel, label='Update db', size=(100, 30))
        hbox2.Add(db_btn, flag=wx.LEFT|wx.BOTTOM, border=5)
        exit_btn = wx.Button(panel, label='Exit', size=(70, 30))
        hbox2.Add(exit_btn, flag=wx.LEFT|wx.BOTTOM, border=5)
        vbox.Add(hbox2, flag=wx.ALIGN_RIGHT|wx.RIGHT, border=10)

        #Setup button bindings
        self.Bind(wx.EVT_BUTTON, self.OnExit,exit_btn)
        self.Bind(wx.EVT_BUTTON, self.OnPlot, graph_btn)
        self.Bind(wx.EVT_BUTTON, self.OnUpdate, db_btn)

        #Probe checkbox choice
        self.Bind(wx.EVT_COMBOBOX, self.OnSelect, cb1)

        panel.SetSizer(vbox)

    def OnExit(self,event):
        dlg = wx.MessageDialog(self,
               "Do you really want to close this application?",
               "Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
        result = dlg.ShowModal()
        dlg.Destroy()
        if result == wx.ID_OK:
            self.Close()

    def OnPlot(self,event):
        #datestring = str(self.dp.GetValue())
        #dateobject = datetime(*(time.strptime(datestring, "%a %d %b %Y %H:%M:%S %Z")[0:6]))
        #date = dateobject.strftime("%d_%B_%Y")
        #print date
        #Angle numpy arrange
        angles = np.arange(-90,91,15)

        col_cnts = np.array([self.numctrl_ccm90.GetValue(),self.numctrl_ccm75.GetValue(),
                             self.numctrl_ccm60.GetValue(),self.numctrl_ccm45.GetValue(),
                             self.numctrl_ccm30.GetValue(),self.numctrl_ccm15.GetValue(),
                             self.numctrl_cc0.GetValue(),
                             self.numctrl_ccp15.GetValue(),self.numctrl_ccp30.GetValue(),
                             self.numctrl_ccp45.GetValue(),self.numctrl_ccp60.GetValue(),
                             self.numctrl_ccp75.GetValue(),self.numctrl_ccp90.GetValue()])


        #read in collimated counts
        uncol_cnts = np.array([self.numctrl_ucm90.GetValue(),self.numctrl_ucm75.GetValue(),
                             self.numctrl_ucm60.GetValue(),self.numctrl_ucm45.GetValue(),
                             self.numctrl_ucm30.GetValue(),self.numctrl_ucm15.GetValue(),
                             self.numctrl_uc0.GetValue(),
                             self.numctrl_ucp15.GetValue(),self.numctrl_ucp30.GetValue(),
                             self.numctrl_ucp45.GetValue(),self.numctrl_ucp60.GetValue(),
                             self.numctrl_ucp75.GetValue(),self.numctrl_ucp90.GetValue()])


        #Plot col counts vs angle, blue squares
        plt.plot(angles,col_cnts,'bs')

        print col_cnts
        print uncol_cnts



    def OnUpdate(self,event):
        print "Updating non-existant database\n"

    def OnSelect(self,event):
        self.default_probe = self.probe_list[event.GetSelection()]

if __name__ == '__main__':

    app = wx.App()
    NeoProbe(None, title='Neoprobe QC Application')
    app.MainLoop()

编辑

我现在已经设法将我的面板分成上下面板。但是空间管理很差。最后一个 NumCtrl 和上面板中的按钮之间的差距很大。另外我不知道如何将我的图形放在下面板的中心位置并根据面板大小调整它的大小

import wx

from wx.lib.masked import NumCtrl
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.use('WXAgg')
import matplotlib.backends.backend_wxagg as mwx
import numpy as np
import pylab
from datetime import datetime
import time

class NeoProbe(wx.Frame):
    def __init__(self, parent, title):
        super(NeoProbe, self).__init__(parent, title=title, 
            size=(750, 900))

        panel = wx.Panel(self)
        vsizer = wx.BoxSizer(wx.VERTICAL)

        top_panel = wx.Panel(panel)
        vsizer.Add(top_panel, 1, wx.EXPAND)
        top_panel_sizer = wx.BoxSizer(wx.VERTICAL)
        top_panel.SetSizer(top_panel_sizer)

        bottom_panel = wx.Panel(panel)
        vsizer.Add(bottom_panel, 1, wx.EXPAND)
        bottom_panel_sizer = wx.BoxSizer(wx.VERTICAL)
        bottom_panel.SetSizer(bottom_panel_sizer)

        self.midPanel = wx.Panel(bottom_panel)
        bottom_panel_sizer.Add(self.midPanel, 1, wx.EXPAND | wx.ALL, 20)

        top_panel_sizer = wx.BoxSizer(wx.VERTICAL)
        top_panel.SetSizer(top_panel_sizer)

        panel.SetSizer(vsizer)

        self.probe_list = ['Old','New']
        #default probe is old
        self.default_probe = self.probe_list[0]

        font = wx.SystemSettings_GetFont(wx.SYS_SYSTEM_FONT)
        font.SetPointSize(9)

        vbox = wx.BoxSizer(wx.VERTICAL)

        hbox1 = wx.BoxSizer(wx.HORIZONTAL)
        st1 = wx.StaticText(top_panel, label='Date')
        st1.SetFont(font)
        hbox1.Add(st1, flag=wx.RIGHT, border=8)
        self.dp = wx.DatePickerCtrl(top_panel,wx.ID_ANY,wx.DefaultDateTime,wx.DefaultPosition)
        self.dp.SetFont(font)
        hbox1.Add(self.dp,flag=wx.RIGHT,border=10)
        hbox1.Add((80,1))
        st2 = wx.StaticText(top_panel, label='Probe')
        st2.SetFont(font)
        hbox1.Add(st2, flag=wx.RIGHT, border=8)

        cb1 = wx.ComboBox(top_panel,wx.ID_ANY,choices = self.probe_list,
                          value=self.default_probe,
                          style=wx.TE_PROCESS_ENTER,size=(100, 30))
        cb1.SetFont(font)
        hbox1.Add(cb1,proportion=0,flag=wx.ALIGN_RIGHT|wx.LEFT, border =10)
        vbox.Add(hbox1, flag=wx.LEFT|wx.RIGHT|wx.TOP, border=10)

        ## Now add grid sizer
        fgs = wx.FlexGridSizer(10,6,9,25)
        bfont = wx.Font(10,wx.DEFAULT,wx.NORMAL,wx.BOLD)
        angle = wx.StaticText(top_panel,label="Angle")
        angle.SetFont(bfont)
        count_c = wx.StaticText(top_panel,label="Counts (C)")
        count_c.SetFont(bfont)
        count_u = wx.StaticText(top_panel,label="Counts (U)")
        count_u.SetFont(bfont)
        angle2 = wx.StaticText(top_panel,label="Angle")
        angle2.SetFont(bfont)
        count_c2 = wx.StaticText(top_panel,label="Counts (C)")
        count_c2.SetFont(bfont)
        count_u2 = wx.StaticText(top_panel,label="Counts (U)")
        count_u2.SetFont(bfont)

        #Set input boxes for results
        self.numctrl_ccm90 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucm90 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccp90 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucp90 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccm75 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucm75 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccp75 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucp75 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccm60 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucm60 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccp60 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucp60 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccm45 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucm45 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccp45 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucp45 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccm30 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucm30 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccp30 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucp30 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccm15 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucm15 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ccp15 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_ucp15 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_cc0 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_uc0 = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)
        self.numctrl_fwhm = NumCtrl(top_panel,-1,style=wx.TE_PROCESS_ENTER|wx.TE_PROCESS_TAB)

        fgs.AddMany([(angle),(count_c), (count_u),(angle2),(count_c2), (count_u2),
                     (wx.StaticText(top_panel, -1, '-90')),
                     (self.numctrl_ccm90,0,wx.EXPAND,5),
                     (self.numctrl_ucm90,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, '90')),
                     (self.numctrl_ccp90,0,wx.EXPAND,5),
                     (self.numctrl_ucp90,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, '-75')),
                     (self.numctrl_ccm75,0,wx.EXPAND,5),
                     (self.numctrl_ucm75,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, '75')),
                     (self.numctrl_ccp75,0,wx.EXPAND,5),
                     (self.numctrl_ucp75,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, '-60')),
                     (self.numctrl_ccm60,0,wx.EXPAND,5),
                     (self.numctrl_ucm60,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, '60')),
                     (self.numctrl_ccp60,0,wx.EXPAND,5),
                     (self.numctrl_ucp60,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, '-45')),
                     (self.numctrl_ccm45,0,wx.EXPAND,5),
                     (self.numctrl_ucm45,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, '45')),
                     (self.numctrl_ccp45,0,wx.EXPAND,5),
                     (self.numctrl_ucp45,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, '-30')),
                     (self.numctrl_ccm30,0,wx.EXPAND,5),
                     (self.numctrl_ucm30,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, '30')),
                     (self.numctrl_ccp30,0,wx.EXPAND,5),
                     (self.numctrl_ucp30,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, '-15')),
                     (self.numctrl_ccm15,0,wx.EXPAND,5),
                     (self.numctrl_ucm15,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, '15')),
                     (self.numctrl_ccp15,0,wx.EXPAND,5),
                     (self.numctrl_ucp15,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, '0')),
                     (self.numctrl_cc0,0,wx.EXPAND,5),
                     (self.numctrl_uc0,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, 'FWHM')),
                     (self.numctrl_fwhm,0,wx.EXPAND,5),
                     (wx.StaticText(top_panel, -1, 'deg'))])


        vbox.Add(fgs, proportion=1,flag = wx.LEFT | wx.RIGHT |wx.ALIGN_CENTER,border=5)

        hbox2 = wx.BoxSizer(wx.HORIZONTAL)
        graph_btn = wx.Button(top_panel, label='Plot', size=(70, 30))
        hbox2.Add(graph_btn)
        db_btn = wx.Button(top_panel, label='Update db', size=(100, 30))
        hbox2.Add(db_btn, flag=wx.LEFT|wx.BOTTOM, border=5)
        exit_btn = wx.Button(top_panel, label='Exit', size=(70, 30))
        hbox2.Add(exit_btn, flag=wx.LEFT|wx.BOTTOM, border=5)
        vbox.Add(hbox2, flag=wx.ALIGN_RIGHT|wx.RIGHT, border=10)

        #Setup button bindings
        self.Bind(wx.EVT_BUTTON, self.OnExit,exit_btn)
        self.Bind(wx.EVT_BUTTON, self.OnPlot, graph_btn)
        self.Bind(wx.EVT_BUTTON, self.OnUpdate, db_btn)

        #Probe checkbox choice
        self.Bind(wx.EVT_COMBOBOX, self.OnSelect, cb1)

        top_panel.SetSizer(vbox)


        self.Centre()
        self.Show()

    def OnExit(self,event):
        dlg = wx.MessageDialog(self,
               "Do you really want to close this application?",
               "Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
        result = dlg.ShowModal()
        dlg.Destroy()
        if result == wx.ID_OK:
            self.Close()

    def OnPlot(self,event):
        #datestring = str(self.dp.GetValue())
        #dateobject = datetime(*(time.strptime(datestring, "%a %d %b %Y %H:%M:%S %Z")[0:6]))
        #date = dateobject.strftime("%d_%B_%Y")
        #print date
        #Angle numpy arrange
        angles = np.arange(-90,91,15)

        col_cnts = np.array([self.numctrl_ccm90.GetValue(),self.numctrl_ccm75.GetValue(),
                             self.numctrl_ccm60.GetValue(),self.numctrl_ccm45.GetValue(),
                             self.numctrl_ccm30.GetValue(),self.numctrl_ccm15.GetValue(),
                             self.numctrl_cc0.GetValue(),
                             self.numctrl_ccp15.GetValue(),self.numctrl_ccp30.GetValue(),
                             self.numctrl_ccp45.GetValue(),self.numctrl_ccp60.GetValue(),
                             self.numctrl_ccp75.GetValue(),self.numctrl_ccp90.GetValue()])


        #read in collimated counts
        uncol_cnts = np.array([self.numctrl_ucm90.GetValue(),self.numctrl_ucm75.GetValue(),
                             self.numctrl_ucm60.GetValue(),self.numctrl_ucm45.GetValue(),
                             self.numctrl_ucm30.GetValue(),self.numctrl_ucm15.GetValue(),
                             self.numctrl_uc0.GetValue(),
                             self.numctrl_ucp15.GetValue(),self.numctrl_ucp30.GetValue(),
                             self.numctrl_ucp45.GetValue(),self.numctrl_ucp60.GetValue(),
                             self.numctrl_ucp75.GetValue(),self.numctrl_ucp90.GetValue()])


        #Plot col counts vs angle, blue squares
        fig = mpl.figure.Figure()
        canvas = mwx.FigureCanvasWxAgg(self.midPanel, -1, fig)
        ax = fig.add_subplot(1, 1, 1)
        ax.plot(angles,col_cnts,'bs')
        canvas.draw()

        print col_cnts
        print uncol_cnts



    def OnUpdate(self,event):
        print "Updating non-existant database\n"

    def OnSelect(self,event):
        self.default_probe = self.probe_list[event.GetSelection()]


if __name__ == '__main__':        
    app = wx.App()
    NeoProbe(None, title='Neoprobe QC Application')
    app.MainLoop()
4

1 回答 1

3

您需要创建一个图形,其代码类似于:

import matplotlib as mpl
mpl.use('WXAgg')
import matplotlib.backends.backend_wxagg as mwx

fig = mpl.figure.Figure()
canvas = mwx.FigureCanvasWxAgg(panel, -1, fig)
ax = fig.add_subplot(1, 1, 1)
ax.plot(...)
canvas.draw()

有关可运行的示例,请参阅Matplotlib 示例库

于 2013-07-29T12:38:37.497 回答