-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathviz_metasources.py
58 lines (48 loc) · 1.67 KB
/
viz_metasources.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Fri Aug 9 16:57:46 2019
@author: lavanyasingh
"""
import csv
from matplotlib import pyplot as plt
class Viz_Maker:
def __init__(self, infile="data/all_raw_cleaned.csv"):
self.infile=infile
def read_in(self):
sources = []
with open(self.infile, 'r') as f:
reader = csv.reader(f, delimiter=',')
for line in reader:
sources.append([line[1], line[7].split(" ")])
print("DONE READING")
return sources
def ms_bar_chart(self):
sources = self.read_in()
data = {}
for source in sources:
metasources = source[1]
for ms in metasources:
if ms != "":
try:
data[ms] += 1
except KeyError:
data.update({ms:1})
datalist = [(val, key) for key, val in data.items()]
top = sorted(datalist, reverse=True)
y = [element[1] for element in top]
x = [element[0] for element in top]
plt.bar(y, x, align='center', alpha=1, color="#141d99")
plt.xlabel('Metasources', fontsize=15)
plt.ylabel('Number of Sources', fontsize = 15)
plt.xticks(y, y, rotation='vertical')
plt.box(False)
plt.tick_params(axis='both', length = 0)
plt.locator_params(axis='y', nbins=4)
plt.title("World News Project Metasources", fontsize=18)
plt.tight_layout()
plt.show()
if __name__ == '__main__':
viz_maker = Viz_Maker()
viz_maker.ms_bar_chart()
#clean_ms()