一、艾略特波段理论实战(2):中8浪
前面介绍了艾略特波段理论的实战(1),本文在此基础上进行了进一步的探讨。将原来8浪中的第1、2、3、4、5作为中8浪的第1浪,原来8浪中的a、b、c浪作为中8浪的第2浪,然后按照原来8浪的规律进而画出整个中8浪。
二、代码实现
import matplotlib
import matplotlib.pyplot as plt # 导入matplotlib包的子模块pyplot,并将其重命名为plt
import numpy as np # 导入numpy,并将其重命名为np
matplotlib.rcParams['font.sans-serif'] = ['SimHei'] # 显示中文
# 为了坐标轴负号正常显示。matplotlib默认不支持中文,设置中文字体后,负号会显示异常。需要手动将坐标轴负号设为False才能正常显示负号。
matplotlib.rcParams['axes.unicode_minus'] = False
x = np.linspace(0, 13, 1000) # 横轴
x_02 = np.linspace(0, 52, 1000) # 更大一级8段循环的横轴
x_list = x.tolist() # 横轴数据转化为列表
x_list_02 = x_02.tolist()
y_list = [] # 纵轴数据列表
y_list_02 = [] # 更大一级8段循环的纵轴数据列表
# 8段循环函数
for a in x_list:
if 0 <= a and a < 2:
y = 1 * a
y_list.append(y)
elif 2 <= a and a < 3:
y = -1 * a + 4
y_list.append(y)
elif 3 <=a and a < 5:
y = 1 * a - 2
y_list.append(y)
elif 5 <= a and a < 6:
y = -1 * a + 8
y_list.append(y)
elif 6 <= a and a < 8:
y = 1 * a - 4
y_list.append(y)
elif 8 <= a and a < 10:
y = -0.618 * a + 8.944
y_list.append(y)
elif 10 <= a and a < 11:
y = 0.618 * a - 3.416
y_list.append(y)
elif 11 <= a <= 13:
y = -0.618 *a + 10.18
y_list.append(y)
# 更大一级8段循环函数
for a in x_list_02:
if 0 <= a and a < 8:
y = 0.5 * a
y_list_02.append(y)
elif 8 <= a and a < 13:
y = -0.3708 * a + 6.9664
y_list_02.append(y)
elif 13 <=a and a < 21:
y = 0.5 * a - 4.354
y_list_02.append(y)
elif 21 <= a and a < 26:
y = -0.3708 * a + 13.9328
y_list_02.append(y)
elif 26 <= a and a < 32:
y = 0.5 * a - 8.708
y_list_02.append(y)
elif 32 <= a and a < 40:
y = -0.23175 * a + 14.708
y_list_02.append(y)
elif 40 <= a and a < 44:
y = 0.23175 * a - 3.832
y_list_02.append(y)
elif 44 <= a <= 52:
y = -0.23175 *a + 16.562
y_list_02.append(y)
plt.plot(x_list, y_list, label='小8浪') # 画图
plt.plot(x_list_02, y_list_02, label='中8浪') # 画图
plt.legend(loc=0) # 给图片在右上角添加图例
plt.xlabel('x')
plt.ylabel('y')
plt.title('8浪循环图2')
plt.savefig(r"D:\u_career\i_coder\i_python\波浪理论实践\8浪循环图2.jpg") # 保存到本地
plt.show()