parent
c36be03399
commit
74458dfe62
@ -0,0 +1,52 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Fri Dec 2 22:10:31 2022
|
||||
|
||||
@author: DELL
|
||||
"""
|
||||
|
||||
import datetime
|
||||
import pandas as pd
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
with open('information.txt','r',encoding='utf-8') as fe:
|
||||
info=fe.read()
|
||||
lst=info.split(' ')
|
||||
date1 = datetime.datetime.strptime(lst[2],"%Y-%m-%d")
|
||||
date2 = date1 + datetime.timedelta(days=int(lst[3]))
|
||||
df = pd.read_csv("contentt.csv", encoding=('gb2312'),names=["date","flightNum", "depTime", "arrTime", "price"])
|
||||
df.head()
|
||||
df1 = df.groupby("date").count()["flightNum"]
|
||||
plt.rcParams['font.sans-serif'] = ['SimHei']
|
||||
plt.rcParams['figure.figsize'] = (13, 8)
|
||||
|
||||
x = np.arange(int(lst[3]))
|
||||
|
||||
#x=df1.index
|
||||
pricmax=[]
|
||||
pricmin=[]
|
||||
for i in range(int(lst[3])):
|
||||
date1 = date1 + datetime.timedelta(days=1)
|
||||
df2=df[df.date==str(date1)[0:10]]
|
||||
pric=df2['price'].max()
|
||||
pricm=df2['price'].min()
|
||||
pricmax.append(pric)
|
||||
pricmin.append(pricm)
|
||||
|
||||
bar_width = 0.35
|
||||
plt.bar(x,pricmin,bar_width,align="center",label="min",alpha=0.5)
|
||||
plt.bar(x+bar_width,pricmax,bar_width,align="center",label="max",alpha=0.5)
|
||||
plt.xticks(x+bar_width/2,df1.index.tolist())
|
||||
|
||||
x=df1.index
|
||||
for a, b in zip(df1.index.tolist(), pricmax):
|
||||
plt.text(a, b, b, ha='left', va='bottom', fontsize=20,color='firebrick')
|
||||
for a, b in zip(df1.index.tolist(), pricmin):
|
||||
plt.text(a, b, b, ha='center', va='top', fontsize=20,color='teal')
|
||||
plt.xlabel("日期",fontsize=14)
|
||||
plt.ylabel("机票价格",fontsize=14)
|
||||
plt.plot(x, pricmin, marker="v",color='steelblue')
|
||||
|
||||
x = np.arange(int(lst[3]))
|
||||
plt.plot(x+bar_width, pricmax, marker="^",color='indianred')
|
||||
plt.xticks(x+bar_width/2,df1.index.tolist())
|
Loading…
Reference in new issue