from pathlib import Path

import numpy as np
import pandas as pd
from pandas import DataFrame, Series
import matplotlib.pyplot as plt
from sklearn.preprocessing import MinMaxScaler


def pic_simple(x_y_df: DataFrame, x_interval=100):
    plt.figure(figsize=(5, 3))

    idx = x_y_df.index.values.tolist()
    close1 = MinMaxScaler().fit_transform(x_y_df)
    close1 = close1.reshape(-1)
    print(len(close1))
    plt.plot(x_y_df.index, close1)

    plt.xticks(idx, idx)
    xticks = list(range(0, len(idx), x_interval)) # len(idx)//10
    ax = plt.gca()
    ax.set_xticks([0, 23, 43, 62])
    plt.axvline(x=0, ls="--", c="green")  # 添加垂直直线
    plt.axvline(x=23, ls="--", c="green")  # 添加垂直直线
    plt.axvline(x=43, ls="--", c="green")  # 添加垂直直线
    plt.axvline(x=62, ls="--", c="green")  # 添加垂直直线
    plt.title('S&P500')


''' 波动 暴跌 暴涨 '''
df = pd.read_csv('SPX.GI', index_col=0)
t = df.loc['2019-04-01': '2019-06-28', ['CLOSE']]
pic_simple(t, 10)
plt.savefig(Path('./') / 'Test Set', dpi=300, bbox_inches='tight')
plt.show()