import numpy as np
import pandas as pd
import datetime
import re
import time
import glob
import copy
import matplotlib.dates as mdate
from scipy.interpolate import make_interp_spline
from scipy.interpolate import interp1d
from matplotlib import pyplot as plt
dateparse = lambda date: pd.datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
df =pd.read_csv(r'.17-20.csv',encoding='utf-8',parse_dates=['date'],date_parser=dateparse)
s = np.array(df['h1'])
d = len(s)
helper = pd.DataFrame({'date': pd.date_range(df['date'].min(), df['date'].max(), freq='0.125H')})
d1 = len(helper['date'])
a = np.linspace(0,d,d)
a_1 = np.linspace(0,d,(d1))
p = make_interp_spline(a,s)(a_1)
p1 = pd.Series(p)
print(p1)
df1 = pd.merge(df,helper,on='date',how='outer').sort_values('date')
df1.reset_index(inplace=True,drop=True)
df1['h2'] =p1
print(df1)
df1.set_index(['date'],inplace=True)
df.set_index(['date'],inplace=True)
plt.rcParams['font.sans-serif'] = 'Simhei'
fig = plt.figure(figsize=(16, 8))
# ax1 = fig.add_subplot(2,2,1)
# ax1.xaxis.set_major_formatter(mdate.DateFormatter('%Y-%m-%d %H:%M:%S'))
# plt.xticks(pd.date_range(df.index[0],df.index[-1],freq='0.25D'),rotation=90)
# ax1.plot(df.index, df['h1'], color='g', label='深度')
# # plt.show()
ax2 = fig.add_subplot(111)
ax2.xaxis.set_major_formatter(mdate.DateFormatter('%Y-%m-%d %H:%M:%S'))
plt.xticks(pd.date_range(df1.index[0],df1.index[-1],freq='0.125D'),rotation=45)
ax2.plot(df1.index, df1['h2'], color='g', label='深度')
ax2.plot(df.index, df['h1'], color='r', label='深度')
plt.show()