forked from anastasyaviviana/Final-Project-JCDS05
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot.py
64 lines (57 loc) · 2.02 KB
/
plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from yahoo_historical import Fetcher
import matplotlib.pyplot as plt
import numpy as np
def dataset(saham,tanggal1,tanggal2):
real_saham=Fetcher("{}.JK".format(saham), tanggal1, tanggal2, interval="1d")
real_saham=real_saham.getHistorical()
real_saham=real_saham.dropna()
return real_saham
#data machine learning
tanggal1=[2012,7,12]
tanggal2=[2019,7,12]
bbri=dataset('BBRI',tanggal1,tanggal2)
bbca=dataset('BBCA',tanggal1,tanggal2)
bbni=dataset('BBNI',tanggal1,tanggal2)
bmri=dataset('BMRI',tanggal1,tanggal2)
plt.figure(figsize=(12,8))
plt.subplot(1,1,1)
plt.plot(np.arange(len(bbri)),bbri['Open'],color='blue',label='Real stock price of BBRI')
plt.plot(np.arange(len(bbri)),bbca['Open'],color='red',label='Real stock price of BBCA')
plt.plot(np.arange(len(bbri)),bbni['Open'],color='green',label='Real stock price of BBNI')
plt.plot(np.arange(len(bbri)),bmri['Open'],color='orange',label='Real stock price of BMRI')
plt.title('Real Stock Price')
plt.xlabel('Date')
plt.ylabel('Stock price')
# plt.xticks(bbri['Date'],rotation=90)
plt.legend()
plt.tight_layout()
# namafile='realdata'
# addressplot='./storage/{}.png'.format(namafile)
# plt.savefig(addressplot)
#Percentage based on popularity
tanggal1=[2018,7,19]
tanggal2=[2019,7,19]
bbri=dataset('BBRI',tanggal1,tanggal2)
bbca=dataset('BBCA',tanggal1,tanggal2)
bbni=dataset('BBNI',tanggal1,tanggal2)
bmri=dataset('BMRI',tanggal1,tanggal2)
sumbbri=bbri.Volume.sum()
sumbbca=bbca.Volume.sum()
sumbbni=bbni.Volume.sum()
sumbmri=bmri.Volume.sum()
#plot percentage popularity in one year
labels = ['BBRI','BBCA','BBNI','BMRI']
sizes = [sumbbri,sumbbca,sumbbni,sumbmri]
fig1, ax1 = plt.subplots()
ax1.pie(sizes, labels=labels, autopct='%1.1f%%',startangle=90)
plt.title('Percentage of Stock Based On Populatity in 1 Year')
#draw circle
centre_circle = plt.Circle((0,0),0.70,fc='white')
fig = plt.gcf()
fig.gca().add_artist(centre_circle)
ax1.axis('equal')
plt.tight_layout()
namafile='plotpopularity'
addressplot='./static/images/{}.png'.format(namafile)
plt.savefig(addressplot)
plt.show()