1

我正在运行 Mac OS X 10.8.4 和 Python 2.7。

我只是想在python中制作一个散点图。在我开始输入关于图形的线条之前,它运行得很好。所以当我包含 window = plt.figure() 时。

这是我的代码:

import csv
import numpy as np
import matplotlib.pyplot as plt
# this program will graph things on a scatter plot

def scatter(filename):
    flux_array =[]
    ratio_array = []
    with open(filename, "U") as csvfile:
        reader = csv.reader(csvfile, delimiter = ',', quoting = csv.QUOTE_NONNUMERIC)
        for row in reader: 
            flux_array.append(row[0])
            ratio_array.append(row[1])
    window = plt.figure()
    plot = window.add_subplot(111, autoscale_on = True) #sets up plot in figure\
    plot.set_title("H-aplha vs. H-alpha/H-beta")
    plot.set_xlabel("H-aplha")
    plot.set_ylabel("ratio")
    plot.scatter(flux_array,ratio_array, 10, "b")
    window.show()

if __name__ == "__main__":
scatter('/Users/Emily/Documents/MMO_2013/Graphs/sample.csv')

这是我得到的错误:(对不起,它真的很长)弹出一个新窗口,标题为“Python已意外退出”,在窗口的其余部分显示:

Process:         Python [23039]
Path:            /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
Identifier:      org.python.python
Version:         2.7.0 (2.7.0)
Code Type:       X86 (Native)
Parent Process:  Python [23034]
User ID:         501

Date/Time:       2013-06-20 16:44:34.145 -0400
OS Version:      Mac OS X 10.8.4 (12E55)
Report Version:  10

Interval Since Last Report:          14896 sec
Crashes Since Last Report:           6
Per-App Interval Since Last Report:  26 sec
Per-App Crashes Since Last Report:   6
Anonymous UUID:                      9498690C-E00D-5F98-DA9B-09FF275B2770

Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000

Application Specific Information:
abort() called

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread

0   libsystem_kernel.dylib          0x96e0ea6a __pthread_kill + 10

1   libsystem_c.dylib               0x95a9cb2f pthread_kill + 101

2   libsystem_c.dylib               0x95ad34ec abort + 168

3   Tcl                             0x02a9cd93 Tcl_PanicVA + 229

4   Tcl                             0x02a9cdae Tcl_Panic + 27

5   Tcl                             0x02a7324d 0x2a20000 + 340557

6   Tcl                             0x02a68626 TclStackAlloc + 60

7   Tcl                             0x02a94ddf TclResetShadowedCmdRefs + 31

8   Tcl                             0x02a2c35b Tcl_CreateCommand + 432

9   _tkagg.so                       0x029f27e0 _tkinit(_object*, _object*) + 112

10  org.python.python               0x000ca3e0 PyEval_EvalFrameEx + 20720

11  org.python.python               0x000cc4ba PyEval_EvalCodeEx + 2042

12  org.python.python               0x000ca471 PyEval_EvalFrameEx + 20865

13  org.python.python               0x000cc4ba PyEval_EvalCodeEx + 2042

14  org.python.python               0x000ca471 PyEval_EvalFrameEx + 20865

15  org.python.python               0x000cc4ba PyEval_EvalCodeEx + 2042

16  org.python.python               0x00041ca2 function_call + 162

17  org.python.python               0x0000f375 PyObject_Call + 85

18  org.python.python               0x000c7d5b PyEval_EvalFrameEx + 10859

19  org.python.python               0x000cc4ba PyEval_EvalCodeEx + 2042

20  org.python.python               0x00041ca2 function_call + 162

21  org.python.python               0x0000f375 PyObject_Call + 85

22  org.python.python               0x00021c66 instancemethod_call + 422

23  org.python.python               0x0000f375 PyObject_Call + 85

24  org.python.python               0x000c435e PyEval_CallObjectWithKeywords + 78

25  _tkinter.so                     0x00722ccc PythonCmd + 220

26  Tcl                             0x00737377 TclInvokeStringCommand + 135

27  Tcl                             0x00738fc8 TclEvalObjvInternal + 678

28  Tcl                             0x0075e4e5 TclExecuteByteCode + 2050

29  Tcl                             0x0075dc49 Tcl_ExprObj + 1115

30  Tcl                             0x0073b3fa Tcl_ExprBooleanObj + 40

31  Tcl                             0x007418ba Tcl_IfObjCmd + 210

32  Tcl                             0x00738fc8 TclEvalObjvInternal + 678

33  Tcl                             0x0073a061 EvalEx + 926

34  Tcl                             0x00739cbe Tcl_EvalEx + 50

35  Tk                              0x01006b83 Tk_BindEvent + 4036

36  Tk                              0x0100b2ea TkBindEventProc + 295

37  Tk                              0x01012460 Tk_HandleEvent + 1277

38  Tk                              0x0102ab46 TkDoConfigureNotify + 114

39  Tk                              0x0102a9c5 Tk_MakeWindowExist + 331

40  Tk                              0x0102aa63 Tk_MapWindow + 34

41  Tk                              0x0102379b ArrangePacking + 1750

42  Tcl                             0x00791309 TclServiceIdle + 61

43  Tcl                             0x0078086d Tcl_DoOneEvent + 337

44  Tk                              0x0100c5e0 Tk_UpdateObjCmd + 135

45  Tcl                             0x00738fc8 TclEvalObjvInternal + 678

46  Tcl                             0x007392fd Tcl_EvalObjv + 118

47  _tkinter.so                     0x00724738 Tkapp_Call + 216

48  org.python.python               0x000ca3e0 PyEval_EvalFrameEx + 20720

49  org.python.python               0x000cbc88 PyEval_EvalFrameEx + 27032

50  org.python.python               0x000cc4ba PyEval_EvalCodeEx + 2042

51  org.python.python               0x000ca471 PyEval_EvalFrameEx + 20865

52  org.python.python               0x000cc4ba PyEval_EvalCodeEx + 2042

53  org.python.python               0x000ca471 PyEval_EvalFrameEx + 20865

54  org.python.python               0x000cbc88 PyEval_EvalFrameEx + 27032

55  org.python.python               0x000cc4ba PyEval_EvalCodeEx + 2042

56  org.python.python               0x000caefa PyEval_EvalFrameEx + 23562

57  org.python.python               0x000cc4ba PyEval_EvalCodeEx + 2042

58  org.python.python               0x00041ca2 function_call + 162

59  org.python.python               0x0000f375 PyObject_Call + 85

60  org.python.python               0x000c7d5b PyEval_EvalFrameEx + 10859

61  org.python.python               0x000cc4ba PyEval_EvalCodeEx + 2042

62  org.python.python               0x000ca471 PyEval_EvalFrameEx + 20865

63  org.python.python               0x000cc4ba PyEval_EvalCodeEx + 2042

64  org.python.python               0x000cc647 PyEval_EvalCode + 87

65  org.python.python               0x000f24bf PyRun_StringFlags + 287

66  org.python.python               0x000f25be PyRun_SimpleStringFlags + 78

67  org.python.python               0x00109db8 Py_Main + 1512

68  org.python.python               0x00001f82 0x1000 + 3970

69  org.python.python               0x00001ea9 0x1000 + 3753

Threads 1-6 ...

Thread 0 crashed with X86 Thread State (32-bit):
  eax: 0x00000000  ebx: 0x02ad639d  ecx: 0xbfffba8c  edx: 0x96e0ea6a
  edi: 0xac6efa28  esi: 0x00000006  ebp: 0xbfffbaa8  esp: 0xbfffba8c
   ss: 0x00000023  efl: 0x00000206  eip: 0x96e0ea6a   cs: 0x0000000b
   ds: 0x00000023   es: 0x00000023   fs: 0x00000000   gs: 0x0000000f
  cr2: 0x02ad639d
Logical CPU: 0

Binary Images:
    0x1000 -     0x1ff5 +org.python.python (2.7.0 - 2.7.0) <E493A842-C949-A532-656D-BC10750CCB80> /Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python
    0x5000 -   0x142fe3 +org.python.python (2.7.0, [c] 2004-2008 Python Software Foundation. - 2.7.0) <2815ECAD-BE96-97DE-C757-303EB571862B> /Library/Frameworks/Python.framework/Versions/2.7/Python
  0x2d6000 -   0x2d7fff +time.so (???) <36AF5C9C-9495-3868-8A5A-4706C959F102> 
a lot more lines like this...
/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_locale.so
 0x1554000 -  0x1556ff5 +_csv.so (???) <A4454B5F-D112-B662-F4A5-9B2E3C630DD2> /Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-dynload/_csv.so
 0x161c000 -  0x16bdff9  multiarray.so (27.4) <3A9DA8B8-2C58-3FB0-B491-968A52101BA4> /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/multiarray.so
 0x16d1000 -  0x1708ffe  umath.so (27.4) <F31C1D02-F34A-36F5-847C-16CB5DC6610A> /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/umath.so
 0x1714000 -  0x1725ff7  _sort.so (27.4) <36D7E10C-CC33-3A4A-9717-29F165644354> /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/_sort.so
 0x176a000 -  0x176efff  _dotblas.so (27.4) <C457183A-71CF-39AF-BEDD-8874CB2D190C> /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/_dotblas.so
 0x1772000 -  0x178cff0  scalarmath.so (27.4) <078B9F29-CD28-3635-BCBC-4CFC6B392BEA> /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/scalarmath.so
 0x1791000 -  0x1791ff5 +_weakref.so (???) <CC5A6874-5A1A-4431-FB8B-3CA18F0DDE5D> 
more lines like this...
 0x2e22000 -  0x2e23ffd  com.apple.ironwoodcore (1.1.1 - 1.1.1) <098CE576-3239-3B41-9141-A5BE6E476C84> /System/Library/PrivateFrameworks/SpeechObjects.framework/Versions/A/Frameworks/DictationServicesCore.framework/DictationServicesCore
0x8fe75000 - 0x8fea7e57  dyld (210.2.3) <23516BE4-29BE-350C-91C9-F36E7999F0F1> /usr/lib/dyld
0x90007000 - 0x9000ffff  libcopyfile.dylib (89) <4963541B-0254-371B-B29A-B6806888949B> /usr/lib/system/libcopyfile.dylib
a lot more lines like this...
/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libvDSP.dylib

External Modification Summary:
  Calls made by other processes targeting this process:
    task_for_pid: 2
    thread_create: 0
    thread_set_state: 0
  Calls made by this process:
    task_for_pid: 0
    thread_create: 0
    thread_set_state: 0
  Calls made by all processes on this machine:
    task_for_pid: 818
    thread_create: 1
    thread_set_state: 0
Model: MacBookPro7,1, BootROM MBP71.0039.B0E, 2 processors, Intel Core 2 Duo, 2.4 GHz, 4 GB, SMC 1.62f7
Graphics: NVIDIA GeForce 320M, NVIDIA GeForce 320M, PCI, 256 MB
Memory Module: BANK 0/DIMM0, 2 GB, DDR3, 1067 MHz, 0x80CE, 0x4D34373142353637334648302D4346382020
Memory Module: BANK 1/DIMM0, 2 GB, DDR3, 1067 MHz, 0x80CE, 0x4D34373142353637334648302D4346382020
AirPort: spairport_wireless_card_type_airport_extreme (0x14E4, 0x8D), Broadcom BCM43xx 1.0 (5.106.98.100.17)

我已经用谷歌搜索了很多,但实际上没有任何答案。

谢谢!

4

2 回答 2

0

我认为您的计算机正在崩溃,因为主线程导致了问题。检查您的 Python 是否损坏,或者您的图形和系统组件是否运行良好。

于 2013-06-21T19:22:50.550 回答
0

这是 IDLE 不知道如何处理 matplotlib 创建的窗口的问题。我需要做的是去终端做:

ipython -pylab

在 [1] 中:运行 file.py

这解决了它。Ipython 知道如何处理与图表的交互性。

于 2013-07-09T18:46:24.297 回答