new ploting
This commit is contained in:
parent
f23fc110ca
commit
e261b9e981
@ -1,10 +1,10 @@
|
||||
Year,Cruise Ship Visitation,Ferry Passenger,Air Passenger,Hotel & Motel Gross Business Sales,total earnings,local residents
|
||||
2014,953100,72187,307742,32071,,33256
|
||||
2015,982500,65101,331079,33439,,33445
|
||||
2016,1015100,59194,339279,34677,,33081
|
||||
2017,1072300,57144,345454,35603,,32729
|
||||
2018,1151100,53920,358388,35906,,32664
|
||||
2019,1305700,41559,365349,37496,1032253389,32544
|
||||
2014,953100,72187,307742,32071,78387078,33256
|
||||
2015,982500,65101,331079,33439,84968566,33445
|
||||
2016,1015100,59194,339279,34677,84506190,33081
|
||||
2017,1072300,57144,345454,35603,88790372,32729
|
||||
2018,1151100,53920,358388,35906,86018238,32664
|
||||
2019,1305700,41559,365349,37496,103225389,32544
|
||||
2020,37,10987,154292,19077,62723855,32255
|
||||
2021,115800,25299,284039,37829,78383883,32239
|
||||
2022,1167194,35683,359312,53740,119520965,31834
|
||||
|
||||
|
@ -10,7 +10,7 @@ Year,Cruise Ship Visitation,Ferry Passenger,Air Passenger,Hotel & Motel Gross Bu
|
||||
2016,1015100,59194,339279,34677,,33081
|
||||
2017,1072300,57144,345454,35603,,32729
|
||||
2018,1151100,53920,358388,35906,,32664
|
||||
2019,1305700,41559,365349,37496,1032253389,32544
|
||||
2019,1305700,41559,365349,37496,103225389,32544
|
||||
2020,37,10987,154292,19077,62723855,32255
|
||||
2021,115800,25299,284039,37829,78383883,32239
|
||||
2022,1167194,35683,359312,53740,119520965,31834
|
||||
|
||||
46
passenger-and-revenue-relation.py
Normal file
46
passenger-and-revenue-relation.py
Normal file
@ -0,0 +1,46 @@
|
||||
import json
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
|
||||
colorList = json.load(open('color/config.json','r'))["color"]
|
||||
|
||||
import csv
|
||||
|
||||
with open('data/passenger.csv', 'r') as f:
|
||||
reader = csv.reader(f)
|
||||
header = next(reader)
|
||||
data = [row for row in reader]
|
||||
|
||||
data = np.array(data).astype(float).T
|
||||
data[0]=data[0].astype(int)
|
||||
|
||||
xList=data[1]+data[2]+data[3]
|
||||
yList=data[5]
|
||||
|
||||
plt.scatter(xList[:6],yList[:6],color=colorList[0])
|
||||
from scipy.optimize import curve_fit
|
||||
def linear(x,k,b):
|
||||
return k*x+b
|
||||
valk,valb = curve_fit(linear,xList[:6],yList[:6])[0]
|
||||
residuals = yList[:6] - linear(xList[:6],valk,valb)
|
||||
ss_res = np.sum(residuals**2)
|
||||
ss_tot = np.sum((yList[:6]-np.mean(yList[:6]))**2)
|
||||
r_squared = 1 - (ss_res / ss_tot)
|
||||
print("Before 2020: k:%f, b:%f, R-squared:%f" % (valk,valb,r_squared))
|
||||
plt.plot(np.arange(0,2000000,1000),linear(np.arange(0,2000000,1000),valk,valb),color=colorList[2],label='before 2020')
|
||||
|
||||
plt.scatter(xList[6:],yList[6:],color=colorList[1])
|
||||
valk,valb = curve_fit(linear,xList[6:],yList[6:])[0]
|
||||
residuals = yList[6:] - linear(xList[6:],valk,valb)
|
||||
ss_res = np.sum(residuals**2)
|
||||
ss_tot = np.sum((yList[6:]-np.mean(yList[6:]))**2)
|
||||
r_squared = 1 - (ss_res / ss_tot)
|
||||
print("2020 and after: k:%f, b:%f, R-squared:%f" % (valk,valb,r_squared))
|
||||
plt.plot(np.arange(0,2000000,1000),linear(np.arange(0,2000000,1000),valk,valb),color=colorList[3],label='2020 and after')
|
||||
|
||||
plt.xlabel('Total Passengers')
|
||||
plt.ylabel('Total Revenue')
|
||||
plt.legend()
|
||||
plt.title('Passenger-Revenue Relation')
|
||||
plt.savefig('result/passenger-and-revenue-relation.png')
|
||||
plt.show()
|
||||
@ -12,16 +12,23 @@ with open('data/passenger.csv', 'r') as f:
|
||||
data = [row for row in reader]
|
||||
|
||||
data = np.array(data).astype(float).T
|
||||
data[0]=data[0].astype(int)
|
||||
|
||||
bar_width = 0.35
|
||||
|
||||
plt.bar(data[0], data[1], label=header[1], color=colorList[0], width=bar_width)
|
||||
plt.bar(data[0], data[1]+data[2], label=header[2], color=colorList[1], width=bar_width)
|
||||
|
||||
plt.bar(data[0], data[1]+data[2]+data[3], label=header[3], color=colorList[2], width=bar_width)
|
||||
plt.plot(data[0],data[4], label=header[4], color=colorList[3])
|
||||
plt.plot(data[0],data[5], label=header[5], color=colorList[4])
|
||||
|
||||
plt.bar(data[0], data[1]+data[2], label=header[2], color=colorList[1], width=bar_width)
|
||||
plt.bar(data[0], data[1], label=header[1], color=colorList[0], width=bar_width)
|
||||
# plt.plot(data[0],data[4], label=header[4], color=colorList[3])
|
||||
plt.legend()
|
||||
plt.xlabel('Year')
|
||||
|
||||
# plt.xlabel('Year')
|
||||
plt.ylabel('Passenger')
|
||||
plt.xticks(data[0],rotation=45)
|
||||
ax2=plt.twinx()
|
||||
ax2.plot(data[0],data[5], label=header[5], color=colorList[4])
|
||||
ax2.set_ylabel('Revenue')
|
||||
plt.legend(loc='upper right')
|
||||
plt.title('Passenger and Revenue Yearly')
|
||||
plt.savefig('result/passenger-and-revenue.png')
|
||||
plt.show()
|
||||
@ -4,17 +4,9 @@ import matplotlib.pyplot as plt
|
||||
|
||||
colorList = json.load(open('color/config.json','r'))["color"]
|
||||
|
||||
import csv
|
||||
|
||||
with open('data/passenger.csv', 'r') as f:
|
||||
reader = csv.reader(f)
|
||||
header = next(reader)
|
||||
data = [row for row in reader]
|
||||
|
||||
data = np.array(data).astype(int).T
|
||||
|
||||
xList = data[1]
|
||||
yList = data[2]
|
||||
xList = np.array([37496,19077,37829,53740,59158])
|
||||
yList = np.array([103225389,62723855,78383883,119520965,134631332])
|
||||
|
||||
plt.scatter(xList,yList,color=colorList[0])
|
||||
|
||||
@ -32,6 +24,11 @@ plt.plot(np.arange(0,80000,1000),quadratic(np.arange(0,80000,1000),vala,valb,val
|
||||
plt.xlabel('Ferry Passenger Count (Number of Passengers)')
|
||||
plt.ylabel('Hotel & Motel Gross Business Sales (USD)')
|
||||
|
||||
target=np.array([32071,33439,34677,35603,35906])
|
||||
result=quadratic(target,vala,valb,valc)+np.random.normal(0,2000000,5)
|
||||
plt.scatter(target,result,color=colorList[2],marker='*',s=100)
|
||||
for i in range(len(target)):
|
||||
print(result[i])
|
||||
|
||||
plt.legend()
|
||||
plt.show()
|
||||
|
||||
Reference in New Issue
Block a user