当前位置 : 主页 > 手机开发 > ROM >

AI_Trade_Model

来源:互联网 收集:自由互联 发布时间:2021-06-10
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, # 设
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()
网友评论