在wxpython中出现问题matplotlib.pyplot.plot

时间:2016-02-10 14:18:43

标签: python matplotlib plot wxpython lines

我有一个用WxPython制作的界面,在Mac OsX中有一些系列算法。

当我运行程序并在不同算法之间进行选择时,我想绘制结果。

但我有一些问题,我不知道为什么matplotlib.pyplot不允许我创建一个情节。这是我得到的错误:

2016-02-10 15:09:19.289 Python[5193:1426611] -[wxNSApplication _setup:]: unrecognized selector sent to instance 0x1020ac450
2016-02-10 15:09:19.289 Python[5193:1426611] -[wxNSApplication _setup:]: unrecognized selector sent to instance 0x1020ac450
2016-02-10 15:09:19.294 Python[5193:1426611] (
0   CoreFoundation                      0x00007fff9021aae2 __exceptionPreprocess + 178
1   libobjc.A.dylib                     0x00007fff967bf73c objc_exception_throw + 48
2   CoreFoundation                      0x00007fff9021db9d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3   CoreFoundation                      0x00007fff90156601 ___forwarding___ + 1009
4   CoreFoundation                      0x00007fff90156188 _CF_forwarding_prep_0 + 120
5   Tk                                  0x00000001089e3958 TkpInit + 476
6   Tk                                  0x000000010895ea7e Tk_Init + 1799
7   _tkinter.so                         0x000000010883bbfd Tcl_AppInit + 77
8   _tkinter.so                         0x000000010883a336 Tkinter_Create + 966
9   Python                              0x00000001000c2f7d PyEval_EvalFrameEx + 21485
10  Python                              0x00000001000c4f93 PyEval_EvalCodeEx + 2115
11  Python                              0x000000010003e990 function_call + 176
12  Python                              0x000000010000cde2 PyObject_Call + 98
13  Python                              0x000000010001f43d instancemethod_call + 365
14  Python                              0x000000010000cde2 PyObject_Call + 98
15  Python                              0x00000001000bc8c7 PyEval_CallObjectWithKeywords + 87
16  Python                              0x000000010002272e PyInstance_New + 126
17  Python                              0x000000010000cde2 PyObject_Call + 98
18  Python                              0x00000001000c0c10 PyEval_EvalFrameEx + 12416
19  Python                              0x00000001000c4f93 PyEval_EvalCodeEx + 2115
20  Python                              0x00000001000c33c0 PyEval_EvalFrameEx + 22576
21  Python                              0x00000001000c4f93 PyEval_EvalCodeEx + 2115
22  Python                              0x000000010003e990 function_call + 176
23  Python                              0x000000010000cde2 PyObject_Call + 98
24  Python                              0x00000001000bf70f PyEval_EvalFrameEx + 7039
25  Python                              0x00000001000c4f93 PyEval_EvalCodeEx + 2115
26  Python                              0x00000001000c33c0 PyEval_EvalFrameEx + 22576
27  Python                              0x00000001000c4f93 PyEval_EvalCodeEx + 2115
28  Python                              0x00000001000c33c0 PyEval_EvalFrameEx + 22576
29  Python                              0x00000001000c4f93 PyEval_EvalCodeEx + 2115
30  Python                              0x00000001000c33c0 PyEval_EvalFrameEx + 22576
31  Python                              0x00000001000c4f93 PyEval_EvalCodeEx + 2115
32  Python                              0x00000001000c33c0 PyEval_EvalFrameEx + 22576
33  Python                              0x00000001000c4f93 PyEval_EvalCodeEx + 2115
34  Python                              0x000000010003e990 function_call + 176
35  Python                              0x000000010000cde2 PyObject_Call + 98
36  Python                              0x000000010001f43d instancemethod_call + 365
37  Python                              0x000000010000cde2 PyObject_Call + 98
38  Python                              0x00000001000bc8c7 PyEval_CallObjectWithKeywords + 87
39  _core_.so                           0x00000001024cc478 _ZN12wxPyCallback12EventThunkerER7wxEvent + 312
40  libwx_osx_cocoau-3.0.0.2.0.dylib    0x00000001031ad094 _ZN12wxEvtHandler23ProcessEventIfMatchesIdERK21wxEventTableEntryBasePS_R7wxEvent + 84
41  libwx_osx_cocoau-3.0.0.2.0.dylib    0x00000001031ae18f _ZN12wxEvtHandler23SearchDynamicEventTableER7wxEvent + 111
42  libwx_osx_cocoau-3.0.0.2.0.dylib    0x00000001031af2f8 _ZN12wxEvtHandler11TryHereOnlyER7wxEvent + 40
43  libwx_osx_cocoau-3.0.0.2.0.dylib    0x00000001031af3ab _ZN12wxEvtHandler19ProcessEventLocallyER7wxEvent + 59
44  libwx_osx_cocoau-3.0.0.2.0.dylib    0x00000001031af415 _ZN12wxEvtHandler12ProcessEventER7wxEvent + 69
45  libwx_osx_cocoau-3.0.0.2.0.dylib    0x00000001031aef86 _ZN12wxEvtHandler18SafelyProcessEventER7wxEvent + 22
46  libwx_osx_cocoau-3.0.0.2.0.dylib    0x00000001033f0960 _ZNK12wxWindowBase17HandleWindowEventER7wxEvent + 16
47  libwx_osx_cocoau-3.0.0.2.0.dylib    0x000000010323f7d9 _ZN9wxControl14ProcessCommandER14wxCommandEvent + 9
48  libwx_osx_cocoau-3.0.0.2.0.dylib    0x000000010320d247 _ZN8wxButton16OSXHandleClickedEd + 71
49  libsystem_trace.dylib               0x00007fff953bf07a _os_activity_initiate + 75
50  AppKit                              0x00007fff979b651d -[NSApplication sendAction:to:from:] + 460
51  AppKit                              0x00007fff979cb486 -[NSControl sendAction:to:] + 86
52  AppKit                              0x00007fff979cb3b0 __26-[NSCell _sendActionFrom:]_block_invoke + 131
53  libsystem_trace.dylib               0x00007fff953bf07a _os_activity_initiate + 75
54  AppKit                              0x00007fff979cb30d -[NSCell _sendActionFrom:] + 144
55  libsystem_trace.dylib               0x00007fff953bf07a _os_activity_initiate + 75
56  AppKit                              0x00007fff979c9932 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2693
57  AppKit                              0x00007fff97a1ed58 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 744
58  AppKit                              0x00007fff979c805c -[NSControl mouseDown:] + 669
59  libwx_osx_cocoau-3.0.0.2.0.dylib    0x00000001032d2d4d _ZN17wxWidgetCocoaImpl10mouseEventEP7NSEventP6NSViewPv + 157
60  AppKit                              0x00007fff97f75d1d -[NSWindow _handleMouseDownEvent:isDelayedEvent:] + 6322
61  AppKit                              0x00007fff97f76fad -[NSWindow _reallySendEvent:isDelayedEvent:] + 212
62  AppKit                              0x00007fff978cf735 -[NSWindow sendEvent:] + 517
63  libwx_osx_cocoau-3.0.0.2.0.dylib    0x00000001032bacfc -[wxNSWindow sendEvent:] + 140
64  AppKit                              0x00007fff978cbe49 -[NSApplication sendEvent:] + 2540
65  libwx_osx_cocoau-3.0.0.2.0.dylib    0x00000001031c16ea -[wxNSApplication sendEvent:] + 74
66  AppKit                              0x00007fff977ff03a -[NSApplication run] + 796
67  libwx_osx_cocoau-3.0.0.2.0.dylib    0x00000001032ab418 _ZN14wxGUIEventLoop8OSXDoRunEv + 248
68  libwx_osx_cocoau-3.0.0.2.0.dylib    0x000000010317860f _ZN13wxCFEventLoop5DoRunEv + 31
69  libwx_osx_cocoau-3.0.0.2.0.dylib    0x00000001030b10e1 _ZN15wxEventLoopBase3RunEv + 65
70  libwx_osx_cocoau-3.0.0.2.0.dylib    0x0000000103076787 _ZN16wxAppConsoleBase8MainLoopEv + 103
71  _core_.so                           0x00000001024c33dc _ZN7wxPyApp8MainLoopEv + 76
72  _core_.so                           0x000000010250dd8f _wrap_PyApp_MainLoop + 79
73  Python                              0x00000001000c2d32 PyEval_EvalFrameEx + 20898
74  Python                              0x00000001000c4f93 PyEval_EvalCodeEx + 2115
75  Python                              0x000000010003e990 function_call + 176
76  Python                              0x000000010000cde2 PyObject_Call + 98
77  Python                              0x000000010001f43d instancemethod_call + 365
78  Python                              0x000000010000cde2 PyObject_Call + 98
79  Python                              0x00000001000c0c10 PyEval_EvalFrameEx + 12416
80  Python                              0x00000001000c3bcf PyEval_EvalFrameEx + 24639
81  Python                              0x00000001000c4f93 PyEval_EvalCodeEx + 2115
82  Python                              0x00000001000c50b6 PyEval_EvalCode + 54
83  Python                              0x00000001000e993e PyRun_FileExFlags + 174
84  Python                              0x00000001000e9bda PyRun_SimpleFileExFlags + 458
85  Python                              0x0000000100100bfd Py_Main + 3101
86  Python                              0x0000000100000f14 Python + 3860
87  ???                                 0x0000000000000002 0x0 + 2
)

Process finished with exit code 143

当我绘制结果时会发生这种情况,如下所示:     pp.plot([1,2,3,4,5])     pp.show

我一直在做一些研究,但我没有找到解决方案。

我尝试以其他方式进行,这是用Canvas做同样的事情等等...但我不能制作线条图,只有条形图,但我需要一个线条图,这是我的代码为了绘制条形图,我不知道如何绘制线条......

class BarsqwFrame(wx.Frame):
title = 'Gráfica'

def __init__(self, dataResults):
    wx.Frame.__init__(self, wx.GetApp().TopWindow, -1, self.title)

    #self.data = dataResults
    self.data = [1, 2, 3, 4, 1, 2, 3, 1, 2, 3, 4, 1]

    self.create_menu()
    self.create_main_panel()
    self.draw_figure()

def create_menu(self):
    self.menubar = wx.MenuBar()

    menu_file = wx.Menu()
    m_expt = menu_file.Append(-1, "&Save plot\tCtrl-S", "Save plot to file")
    self.Bind(wx.EVT_MENU, self.on_save_plot, m_expt)
    menu_file.AppendSeparator()
    m_exit = menu_file.Append(-1, "&Exit\tCtrl-X", "Exit")
    self.Bind(wx.EVT_MENU, self.on_exit, m_exit)

    self.menubar.Append(menu_file, "&File")
    self.SetMenuBar(self.menubar)

def create_main_panel(self):
    """ Creates the main panel with all the controls on it:
         * mpl canvas
         * mpl navigation toolbar
         * Control panel for interaction
    """
    self.panel = wx.Panel(self)

    # Create the mpl Figure and FigCanvas objects.
    # 5x4 inches, 100 dots-per-inch
    #
    self.dpi = 100
    self.fig = Figure((5.0, 4.0), dpi=self.dpi)

    self.canvas = FigCanvas(self.panel, -1, self.fig)

    # Since we have only one plot, we can use add_axes
    # instead of add_subplot, but then the subplot
    # configuration tool in the navigation toolbar wouldn't
    # work.
    #
    self.axes = self.fig.add_subplot(111)

    # Bind the 'pick' event for clicking on one of the bars
    #
    self.canvas.mpl_connect('pick_event', self.on_pick)


    # Create the navigation toolbar, tied to the canvas
    #
    self.toolbar = NavigationToolbar(self.canvas)

    #
    # Layout with box sizers
    #

    self.vbox = wx.BoxSizer(wx.VERTICAL)
    self.vbox.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
    self.vbox.Add(self.toolbar, 0, wx.EXPAND)

    self.hbox = wx.BoxSizer(wx.HORIZONTAL)

    self.vbox.Add(self.hbox, 0, flag = wx.ALIGN_LEFT | wx.TOP)

    self.panel.SetSizer(self.vbox)
    self.vbox.Fit(self)

def draw_figure(self):
    #Redraws the figure
    x = range(len(self.data))
    # clear the axes and redraw the plot anew
    #self.axes.clear()
    #self.axes.Line2D(xdata=x, ydata=self.data)
    #self.axes.bar(left=x, height=self.data, width=0.5, align='center')

    #This lines doesn't make a lines plot...
    #self.axes.barh(bottom=[0,1,2,3], width=[4, 5, 6, 7])
    #self.axes.angle_spectrum(x = [0,1,2,3])
    #self.axes.spy(Z = self.data)

    self.canvas.draw()

def on_pick(self, event):
    # The event received here is of the type
    # matplotlib.backend_bases.PickEvent

    box_points = event.artist.get_bbox().get_points()
    msg = "Has clickeado en las coordenadas:\n %s" % box_points
    dlg = wx.MessageDialog(self, msg, "Click!", wx.OK | wx.ICON_INFORMATION)

    dlg.ShowModal()
    dlg.Destroy()

def on_save_plot(self, event):
    file_choices = "PNG (*.png)|*.png"

    dlg = wx.FileDialog(self, message="Guardar gráfica cómo...", defaultDir=os.getcwd(), defaultFile="plot.png", wildcard=file_choices, style=wx.SAVE)

    if dlg.ShowModal() == wx.ID_OK:
        path = dlg.GetPath()
        self.canvas.print_figure(path, dpi=self.dpi)

def on_exit(self, event):
    self.Destroy()

非常感谢你提前!!!

0 个答案:

没有答案