| |
@@ -73,7 +73,7 @@
|
| |
else:
|
| |
params={'page':1,'rows_per_page':100, 'size':'small'}
|
| |
|
| |
- results= requests.get(baseurl,params=params).json()
|
| |
+ results = requests.get(baseurl,params=params).json()
|
| |
for i in range(results['pages']):
|
| |
for msg in results['raw_messages']:
|
| |
if msg['msg']['created']:
|
| |
@@ -166,5 +166,32 @@
|
| |
|
| |
|
| |
|
| |
- def plot_heat(self,title):
|
| |
- pass
|
| |
+ def plot_heat(self, title='test', filename='base_file', label='label', notebook=False):
|
| |
+ '''plots heatmap with location/number of asked questions '''
|
| |
+ import plotly.plotly as py
|
| |
+ import plotly.graph_objs as go
|
| |
+ from iso3166 import countries
|
| |
+
|
| |
+ ct = Counter(self.members.country_code.values.tolist())
|
| |
+ del ct[None]
|
| |
+
|
| |
+ locations=[]
|
| |
+ z=[]
|
| |
+ names=[]
|
| |
+ for k in ct.keys():
|
| |
+ try:
|
| |
+ country=countries.get(k)
|
| |
+ locations.append(country[2])
|
| |
+ z.append(ct[k])
|
| |
+ names.append(country[0])
|
| |
+ except:
|
| |
+ continue
|
| |
+
|
| |
+ z = pd.Series(z)
|
| |
+ trace = go.Heatmap(z = [z], x = names)
|
| |
+ data = [trace]
|
| |
+
|
| |
+ if notebook:
|
| |
+ return py.iplot(data,filename=filename )
|
| |
+ else:
|
| |
+ return py.plot(data,filename=filename )
|
| |
headmap addition