-
Notifications
You must be signed in to change notification settings - Fork 0
/
bargraph.py
33 lines (28 loc) · 942 Bytes
/
bargraph.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
import matplotlib.pyplot as plt
import os
# positive = 50
# negative = 50
def barchartgenerator(positivecount, negativecount,hotelname):
figure =plt.figure(figsize=(7,5))
filename =hotelname+'.png'
path = os.path.abspath(os.curdir)+'/static/images/'+ filename
names = ["positive Tweets","Negative Tweets"]
scores = [positivecount,negativecount]
total = positivecount+negativecount
scores2 =[total, total]
positions = [0,1]
positions2 = [0.3,1.3]
colors =['green','red']
# if(positive>negative):
# height1 = positive +50
# else:
# height1 = negative +50
plt.bar(positions,scores,width =0.3, color =['red','green'])
plt.bar(positions2, scores2, width=0.3)
plt.xticks(positions, names)
plt.ylabel('Number of Tweets')
figure.savefig(path)
print("Bar graph generated !")
return filename
# plt.show()
# barchartgenerator(200,100,'hyatthotel')