有谁知道如何在tkinter上绘制一个简单的烛台?我正在尝试使用以下MatPlotLib website中的代码并在Sublime Text 3上运行它。但是,经过这么多尝试后,tkinter不会打开,我一直收到此警告:
2016-07-26 13:38:46.546 Python[88018:4981017] -[NSApplication _setup:]: unrecognized selector sent to instance 0x106c42df0
2016-07-26 13:38:46.574 Python[88018:4981017] An uncaught exception was raised
2016-07-26 13:38:46.574 Python[88018:4981017] -[NSApplication _setup:]: unrecognized selector sent to instance 0x106c42df0
2016-07-26 13:38:46.574 Python[88018:4981017] (
0 CoreFoundation 0x00007fff917474f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff966a573c objc_exception_throw + 48
2 CoreFoundation 0x00007fff917b11ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff916b7571 ___forwarding___ + 1009
4 CoreFoundation 0x00007fff916b70f8 _CF_forwarding_prep_0 + 120
5 Tk 0x0000000101677948 TkpInit + 476
6 Tk 0x00000001015f2a6e Tk_Init + 1799
7 _tkinter.cpython-35m-darwin.so 0x00000001003f0dcd Tcl_AppInit + 77
8 _tkinter.cpython-35m-darwin.so 0x00000001003ee7d9 _tkinter_create + 889
9 Python 0x0000000100065479 PyCFunction_Call + 233
10 Python 0x00000001000f1631 PyEval_EvalFrameEx + 36305
11 Python 0x00000001000f2510 _PyEval_EvalCodeWithName + 2368
12 Python 0x00000001000f038b PyEval_EvalFrameEx + 31531
13 Python 0x00000001000f2510 _PyEval_EvalCodeWithName + 2368
14 Python 0x00000001000f2617 PyEval_EvalCodeEx + 71
15 Python 0x000000010004031a function_call + 186
16 Python 0x000000010000d713 PyObject_Call + 99
17 Python 0x00000001000286fc method_call + 140
18 Python 0x000000010000d713 PyObject_Call + 99
19 Python 0x0000000100082a01 slot_tp_init + 81
20 Python 0x0000000100079624 type_call + 212
21 Python 0x000000010000d713 PyObject_Call + 99
22 Python 0x00000001000ec852 PyEval_EvalFrameEx + 16370
23 Python 0x00000001000f2510 _PyEval_EvalCodeWithName + 2368
24 Python 0x00000001000f2671 PyEval_EvalCode + 81
25 Python 0x000000010012083e PyRun_FileExFlags + 206
26 Python 0x0000000100120adf PyRun_SimpleFileExFlags + 447
27 Python 0x0000000100139858 Py_Main + 3512
28 Python 0x0000000100000e32 Python + 3634
29 Python 0x0000000100000c84 Python + 3204
30 ??? 0x0000000000000003 0x0 + 3
)
2016-07-26 13:38:46.575 Python[88018:4981017] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x106c42df0'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff917474f2 __exceptionPreprocess + 178
1 libobjc.A.dylib 0x00007fff966a573c objc_exception_throw + 48
2 CoreFoundation 0x00007fff917b11ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
3 CoreFoundation 0x00007fff916b7571 ___forwarding___ + 1009
4 CoreFoundation 0x00007fff916b70f8 _CF_forwarding_prep_0 + 120
5 Tk 0x0000000101677948 TkpInit + 476
6 Tk 0x00000001015f2a6e Tk_Init + 1799
7 _tkinter.cpython-35m-darwin.so 0x00000001003f0dcd Tcl_AppInit + 77
8 _tkinter.cpython-35m-darwin.so 0x00000001003ee7d9 _tkinter_create + 889
9 Python 0x0000000100065479 PyCFunction_Call + 233
10 Python 0x00000001000f1631 PyEval_EvalFrameEx + 36305
11 Python 0x00000001000f2510 _PyEval_EvalCodeWithName + 2368
12 Python 0x00000001000f038b PyEval_EvalFrameEx + 31531
13 Python 0x00000001000f2510 _PyEval_EvalCodeWithName + 2368
14 Python 0x00000001000f2617 PyEval_EvalCodeEx + 71
15 Python 0x000000010004031a function_call + 186
16 Python 0x000000010000d713 PyObject_Call + 99
17 Python 0x00000001000286fc method_call + 140
18 Python 0x000000010000d713 PyObject_Call + 99
19 Python 0x0000000100082a01 slot_tp_init + 81
20 Python 0x0000000100079624 type_call + 212
21 Python 0x000000010000d713 PyObject_Call + 99
22 Python 0x00000001000ec852 PyEval_EvalFrameEx + 16370
23 Python 0x00000001000f2510 _PyEval_EvalCodeWithName + 2368
24 Python 0x00000001000f2671 PyEval_EvalCode + 81
25 Python 0x000000010012083e PyRun_FileExFlags + 206
26 Python 0x0000000100120adf PyRun_SimpleFileExFlags + 447
27 Python 0x0000000100139858 Py_Main + 3512
28 Python 0x0000000100000e32 Python + 3634
29 Python 0x0000000100000c84 Python + 3204
30 ??? 0x0000000000000003 0x0 + 3
)
libc++abi.dylib: terminating with uncaught exception of type NSException
[Finished in 1.3s with exit code -6]
这是我到目前为止的代码:
from tkinter import *
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter, WeekdayLocator,\
DayLocator, MONDAY
from matplotlib.finance import quotes_historical_yahoo_ohlc, candlestick_ohlc
class App(Tk):
def __init__(self):
Tk.__init__(self)
date1 = (2004, 2, 1)
date2 = (2004, 4, 12)
mondays = WeekdayLocator(MONDAY)
alldays = DayLocator()
weekFormatter = DateFormatter('%b %d')
dayFormatter = DateFormatter('%d')
quotes = quotes_historical_yahoo_ohlc('INTC', date1, date2)
if len(quotes) == 0:
raise SystemExit
fig = Figure(figsize = (7.5, 4.5), dpi = 100)
ax = fig.add_subplot(111)
ax.xaxis.set_major_locator(mondays)
ax.xaxis.set_minor_locator(alldays)
ax.xaxis.set_major_formatter(weekFormatter)
candlestick_ohlc(ax, quotes, width=0.6)
ax.xaxis_date()
ax.autoscale_view()
plt.setp(plt.gca().get_xticklabels(), rotation=45, horizontalalignment='right')
canvas = FigureCanvasTkAgg(fig, self)
canvas.show()
canvas.get_tk_widget().pack(side = TOP, fill = BOTH, expand = False)
if __name__ == "__main__":
app = App()
app.geometry("800x600+51+51")
app.title("Candlestick")
app.mainloop()