AI_Trade_Model

import matplotlib.pyplot as pltfrom matplotlib.animation import FuncAnimationfrom collections import deque# 座標系 fig, ax = plt.subplots()等價於fig, ax = plt.subplots(11)。"""fig = plt.figure()matpltlib.pyplot.figure(num = None,               # 設定figure名稱。系統默認按數字升序命名的figure_num(透視表輸出窗口)e.g. 「figure1」。可自行設定figure名稱,名稱或是INT,或是str類型;figsize=None,             # 設定figure尺寸。系統默認命令是rcParams["figure.fig.size"] = [6.4, 4.8],即figure長寬爲6.4 * 4.8;dpi=None,                 # 設定figure像素密度。系統默命令是rcParams["sigure.dpi"] = 100;facecolor=None,           # 設定figure背景色。系統默認命令是rcParams["figure.facecolor"] = 'w',即白色white;edgecolor=None, frameon=True,    # 設定要不要繪製輪廓&輪廓顏色。系統默認繪製輪廓,輪廓染色rcParams["figure.edgecolor"]='w',即白色white;FigureClass=<class 'matplotlib.figure.Figure'>,   # 設定使不使用一個figure模板。系統默認不使用;clear=False,                     # 設定當同名figure存在時,是否替換它。系統默認False,即不替換。**kwargs)subplot(1,2,1)plot(x, y, 'r--')subplot(1,2,2)plot(y, x, 'g*-')"""# fig, ax = plt.subplots() 等價於下面的兩句# fig = plt.figure()# ax = fig.add_subplot(1, 1, 1)# 其中參數1和2分別表明子圖的行數和列數,一共有 1x1 個子圖像,參數沒有的時候默認一個。fig, ax = plt.subplots(1,1) # 數據源f = open("C:/Users/祥偉/Desktop/USDJPY240.csv", "r")xdate = []ydate = []global xx = 0global dd = 0global prevprev = 0scale = 1.0queue = deque([(0, 0)])for line in f:    #print(line)    values = line.split(",")    price = float(values[5].strip())    if prev == 0:        queue.append((x, price))        prev = price    elif d == 0 and price > prev:        queue.append((x, price))        prev = price    elif d == 0 and price <= prev:        if (prev - price) >= scale:            d = 1            x = x + 1            queue.append((x, prev))            queue.append((x, price))            prev = price                elif d == 1 and price < prev:        queue.append((x, price))        prev = price    elif d == 1 and price >= prev:        if (price - prev) >= scale:            d = 0            x = x + 1            queue.append((x, prev))            queue.append((x, price))            prev = pricedef init():    ax.set_xlim(0, 100)    ax.set_ylim(60, 100)    return ax.plot([], [], "r-", animated=False)def update(frame):    print(frame)    xdate.append(frame[0])    ydate.append(frame[1])    return ax.plot(xdate, ydate, "r-", animated=False)ani = FuncAnimation(fig, update, frames=queue,                    init_func=init, blit=True, repeat=False)plt.show()
本站公眾號
   歡迎關注本站公眾號,獲取更多信息