数据可视化
程序员文章站
2024-02-12 18:13:04
...
import csv
import matplotlib.pyplot as plt
from datetime import datetime
datestring = '159'
def dataload(filename):
date = []
# address = []
count = []
with open(filename) as f:
reader = csv.reader(f)
header_row = next(reader)
for line in reader:
if str(line[1]) == datestring:
date.append(line[0])
# address.append(line[1])
count.append(line[2])
# return date, address, count
return date, count
filename = r'C:\Users\Linger\Desktop\dataACC3_3.csv'
# date, address, count = dataload(filename)
date, count = dataload(filename)
newdate = []
# newaddress = []
newcount = []
for i in range(int(len(count) / 7)):
temp1 = []
temp2 = []
for j in range(7):
temp1.append(date[i * 7 + j])
temp2.append(count[i * 7 + j])
newdate.append(temp1)
newcount.append(temp2)
print(int(len(count) / 7))
fig = plt.figure(figsize=(15,2))
for i in range(0, 6):
plt.subplot(1,6,i+1)
xs = [datetime.strptime(d, '%Y/%m/%d').date() for d in newdate[i]]
plt.plot(xs, newcount[i])
plt.gcf().autofmt_xdate()
fig.tight_layout()
plt.show()
fig = plt.figure(figsize=(15,2))
for i in range(6, 12):
plt.subplot(1,6,i-5)
xs = [datetime.strptime(d, '%Y/%m/%d').date() for d in newdate[i]]
plt.plot(xs, newcount[i])
plt.gcf().autofmt_xdate()
fig.tight_layout()
plt.show()
fig = plt.figure(figsize=(15,2))
for i in range(12, int(len(count) / 7)):
plt.subplot(1,6,i-11)
xs = [datetime.strptime(d, '%Y/%m/%d').date() for d in newdate[i]]
plt.plot(xs, newcount[i])
plt.gcf().autofmt_xdate()
fig.tight_layout()
plt.show()
for i in range(int(len(count) / 7)):
scale = range(7)
xs = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Weekday']
plt.xticks(scale, xs)
plt.plot(newcount[i])
plt.title('TRADE_ADDRESS:'+datestring)
plt.show()
上一篇: DataGear 柱状图 横坐标缺失
下一篇: 思科路由器-配置RIPv2