-
Notifications
You must be signed in to change notification settings - Fork 0
/
correlation.py
82 lines (67 loc) · 2.39 KB
/
correlation.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
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 19 13:29:03 2016
@author: adebayo
"""
from spyre import server
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
import re
import extract
import seaborn as sns
sns.set(color_codes=True)
rs = np.random.RandomState(7)
class CorrelationApp(server.App):
title = "<font color='green'>Compare users' number of followers to friends</font>"
inputs = [{ 'type' : 'slider',
"label": 'Top',
"min" : 0,"max" : 20,"value": 0,
"key": 'top' }]
controls = [{"type" : "button",
"label" : "Plot the Graph",
"id" : "submit_plot"},
{"type" : "button",
"label" : "Load Raw Data",
"id" : "load_table"}]
outputs = [{"type" : "plot",
"id" : "plot1",
"control_id" : "submit_plot",
"tab" : "Bar_Correlation"},
{"type" : "table",
"id" : "table_id",
"control_id" : "load_table",
"tab" : "Data"},
{"type" : "html",
"id" : "custom_html",
"tab" : "Description"}]
tabs = ["Bar_Correlation", "Data", "Description"]
def getData(self, params):
top = int(params['top'])
df = extract.createDataframe()
df.sort_values(by='followers_count', ascending=False, inplace=True)
df2 = df[['screen_name','followers_count', 'friends_count']]
return df2[:top]
def getPlot(self, params):
output_id = params['output_id']
df = self.getData(params)
#fig = plt.figure() # make figure object
#splt = fig.add_subplot(1,1,1)
fig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True)
ind = np.arange(len(df['screen_name']))
width = 0.85
ax0.bar(ind,df['followers_count'], width, color='g')
ax1.bar(ind,df['friends_count'], width, color='y')
ax0.set_ylabel('No of Followers')
ax1.set_ylabel('No of Friends')
#splt.set_title('The top Languages of the Tweets', fontsize=20, fontweight='bold', color='r')
#xTickMarks = ['Group'+str(i) for i in range(1,6)]
ax0.set_xticks(ind+width/2)
ax0.set_xticklabels(df['screen_name'].tolist())
fig.autofmt_xdate(rotation=90)
return fig
def getHTML(self, params):
return "<b>App Description: </b> <i>This application includes bar charts of user's friends and followers.</i>"
if __name__ == '__main__':
app = CorrelationApp()
app.launch(port=9093)