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
time_parse =lambda date: datetime.datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
df =pd.read_csv(r'.总流速.csv',encoding='utf-8',parse_dates=['date'],date_parser=time_parse)
# print(df)
rmcols = ['d']
df.drop(rmcols,inplace=True,axis = 1)
df.set_index(df['date'],inplace=True)
rmcol = ['date']
df.drop(rmcol,inplace=True,axis = 1)
# print(df)
o1 = df.groupby('hb')
o2 = o1.get_group(0)
o3 = o1.get_group(0.2)
o4 = o1.get_group(0.4)
o5 = o1.get_group(0.6)
o6 = o1.get_group(0.8)
o7 = o1.get_group(1)
print(o2)
c1 = o2.index
# print(c1)
# c2 = np.array(c1)
# print(c2)
pt = np.array(o2['val']).reshape(len(o2['val']),1)
pt2 = np.array(o3['val']).reshape(len(o2['val']),1)
pt3 = np.array(o4['val']).reshape(len(o2['val']),1)
pt4 = np.array(o5['val']).reshape(len(o2['val']),1)
pt5 = np.array(o6['val']).reshape(len(o2['val']),1)
pt6 = np.array(o7['val']).reshape(len(o2['val']),1)
# print(pt2)
t = np.hstack((pt,pt2))
t1 = np.hstack((t,pt3))
t2 = np.hstack((t1,pt4))
t3 = np.hstack((t2,pt5))
t4 = np.hstack((t3,pt6))
t4=t4.reshape(6,305)
print(t4.shape)
y = np.linspace(-1,0,6)
# print(y)
x = np.array(c1)
z =t4
# # print(z)
X,Y= np.meshgrid(x,y)
plt.rcParams['font.sans-serif'] = 'Microsoft YaHei'
plt.gca().xaxis.set_major_formatter(mdate.DateFormatter('%Y-%m-%d %H:%M:%S'))
plt.xticks(pd.date_range(o2.index[0],o2.index[-1],freq='0.5D'),rotation=90)
plt.contourf(X,Y,z,cmap = 'jet')
plt.colorbar()
plt.show()