-
Notifications
You must be signed in to change notification settings - Fork 0
/
city_bar_plot.py
197 lines (167 loc) · 6.37 KB
/
city_bar_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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import streamlit as st
import plotly.graph_objects as go
TITLE = 'City Wise Sentiment Analysis'
X_AXIS = 'Month'
Y_AXIS = 'Tweet Count'
LINE_WIDTH = 3
POS_LINE_COLOR = 'rgb(67,230,167)'
NEG_LINE_COLOR = 'rgb(230,100,120)'
NEU_LINE_COLOR = 'rgb(167,167,167)'
SOM_POS_LINE_COLOR = 'lightskyblue'
SOM_NEG_LINE_COLOR = 'palevioletred'
TEXT_COLOR = 'rgb(200,200,200)'
LEGEND_BACKG_COLOR = 'rgb(100,110,120)'
POS_HOVER_TEXT_BACKG_COLOR = "teal"
NEG_HOVER_TEXT_BACKG_COLOR = "crimson"
NEU_HOVER_TEXT_BACKG_COLOR = "slategrey"
ALL_HOVER_TEXT_BACKG_COLOR = "silver"
c1 = ['Mumbai', 'Delhi', 'New Delhi', 'Bangalore', 'Hyderabad', 'Chennai', 'Pune', 'Kolkata', 'Bhubaneswar',
'Ahmedabad', 'Dispur', 'Chandigarh', 'Jaipur', 'Lucknow', 'Jammu', 'Patna', 'Surat', 'Indore', 'Panaji', 'Bhopal']
c2 = ['Mumbai', 'Delhi', 'New Delhi', 'Bangalore', 'Hyderabad', 'Kolkata', 'Chennai', 'Pune', 'Bhubaneswar',
'Ahmedabad', 'Lucknow', 'Chandigarh', 'Dispur', 'Jaipur', 'Jammu', 'Patna', 'Panaji', 'Indore', 'Bhopal', 'Surat']
c3 = ['Mumbai', 'Delhi', 'New Delhi', 'Bangalore', 'Hyderabad', 'Chennai', 'Pune', 'Kolkata', 'Ahmedabad',
'Bhubaneswar', 'Lucknow', 'Dispur', 'Chandigarh', 'Jaipur', 'Patna', 'Jammu', 'Surat', 'Indore', 'Bhopal',
'Panaji']
pos = [29411, 17642, 15852, 13828, 10454, 7344, 7260, 6276, 3768, 3437, 2924, 2731, 2560, 2376, 1531, 1524, 1290, 1149,
1126, 876]
neg = [16915, 10710, 9363, 8226, 5885, 4270, 3986, 3466, 1807, 1679, 1412, 1338, 1301, 1234, 1009, 925, 719, 580, 537,
527]
neut = [43155, 32314, 23952, 21298, 15943, 15868, 10344, 9552, 5307, 4841, 4633, 4197, 4099, 4034, 2850, 2401, 1922,
1884, 1798, 1647]
fig = go.Figure()
def positive(fig):
fig.add_trace(go.Bar(
x=c1,
y=pos,
name='Positive Sentiment',
marker_color=POS_LINE_COLOR
))
fig.update_layout(hoverlabel=dict(
bgcolor=POS_HOVER_TEXT_BACKG_COLOR,
))
# def some_positive(fig):
# fig.add_trace(go.Bar(
# x=cities,
# y=num_som_pos_sent,
# name='Somewhat Positive Sentiment',
# marker_color=SOM_POS_LINE_COLOR
# ))
def negative(fig):
fig.add_trace(go.Bar(
x=c2,
y=neg,
name='Negative Sentiment',
marker_color=NEG_LINE_COLOR
))
fig.update_layout(hoverlabel=dict(
bgcolor=NEG_HOVER_TEXT_BACKG_COLOR,
))
# def some_negative(fig):
# fig.add_trace(go.Bar(
# x=cities,
# y=num_som_neg_sent,
# name='Somewhat Negative Sentiment',
# marker_color=SOM_NEG_LINE_COLOR
# ))
def neutral(fig):
fig.add_trace(go.Bar(
x=c3,
y=neut,
name='Neutral Sentiment',
marker_color=NEU_LINE_COLOR
))
fig.update_layout(hoverlabel=dict(
bgcolor=NEU_HOVER_TEXT_BACKG_COLOR,
))
# Here we modify the tickangle of the xaxis, resulting in rotated labels.
# Changed the background plot color of the graph as well as the paper to Black.
# Changed the font style , size and color.
def plot(theme='plotly_dark'):
pass
def main(theme='plotly_dark', height=650, width=850, sentiment_picker='All'):
# st.title('IBM Hack Challenge 2020')
fig = go.Figure()
global TEXT_COLOR, LEGEND_BACKG_COLOR, NEU_LINE_COLOR, POS_LINE_COLOR, NEG_LINE_COLOR, SOM_POS_LINE_COLOR, SOM_NEG_LINE_COLOR, PLOT_BG_COLOR
if theme == 'plotly':
# global TEXT_COLOR, LEGEND_BACKG_COLOR, NEU_LINE_COLOR, POS_LINE_COLOR, NEG_LINE_COLOR
TEXT_COLOR = 'rgb(100,100,100)'
LEGEND_BACKG_COLOR = 'rgb(200,210,220)'
NEU_LINE_COLOR = 'rgb(97,97,97)'
POS_LINE_COLOR = 'rgb(42,128,97)'
NEG_LINE_COLOR = 'rgb(229,57,53)'
SOM_POS_LINE_COLOR = 'lightgreen'
SOM_NEG_LINE_COLOR = 'orange'
PLOT_BG_COLOR = 'rgb(240,240,240)'
theme = 'plotly'
# st.write(LEGEND_BACKG_COLOR)
else:
POS_LINE_COLOR = 'rgb(67,230,167)'
NEG_LINE_COLOR = 'rgb(230,100,120)'
NEU_LINE_COLOR = 'rgb(167,167,167)'
SOM_POS_LINE_COLOR = 'lightskyblue'
SOM_NEG_LINE_COLOR = 'palevioletred'
TEXT_COLOR = 'rgb(200,200,200)'
LEGEND_BACKG_COLOR = 'rgb(100,110,120)'
PLOT_BG_COLOR = 'rgb(16,16,16)'
theme = 'plotly_dark'
if sentiment_picker == 'Positive':
positive(fig)
# elif sentiment_picker == 'Somewhat Positive':
# some_positive(fig)
elif sentiment_picker == 'Negative':
negative(fig)
# elif sentiment_picker == 'Somewhat Negative':
# some_negative(fig)
elif sentiment_picker == 'Neutral':
neutral(fig)
else:
positive(fig)
# some_positive(fig)
negative(fig)
# some_negative(fig)
neutral(fig)
fig.update_layout(hoverlabel=dict(
bgcolor=ALL_HOVER_TEXT_BACKG_COLOR,
))
# Here we modify the tickangle of the xaxis, resulting in rotated labels.
fig.update_layout(title=TITLE,
xaxis_title=X_AXIS,
yaxis_title=Y_AXIS,
barmode='group', xaxis_tickangle=-45,
# showgrid=False,
template=theme,
font=dict(
family="Courier New, monospace",
size=18,
color=TEXT_COLOR
),
showlegend=True,
legend_title_text='Sentiment',
legend=dict(x=0.77,
y=1,
traceorder="normal",
font=dict(
family="sans-serif",
size=12,
color="black"),
bgcolor=LEGEND_BACKG_COLOR,
bordercolor="beige",
borderwidth=1
),
height=height,
width=width,
margin=dict(
l=50,
r=50,
b=100,
t=100,
pad=4
),
hovermode='x',
hoverlabel=dict(
font_size=16
))
return st.plotly_chart(fig)
# plot()
if __name__ == '__main__':
main()