-
Notifications
You must be signed in to change notification settings - Fork 8
/
plots.py
60 lines (48 loc) · 1.75 KB
/
plots.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
import matplotlib
matplotlib.use('Agg') # (ノಠ益ಠ)ノ彡┻━┻
import pandas as pd
import matplotlib.pyplot as plt
import re
import sys
def account_spend_plot(csvfile=None, outputfilename=None, outputfiletype="png"):
"""
creates a plot for account-based spends
args:
csvfile: full path to the CSV file
outputfilename: name (without extension) of the outputted plot
outputfiletype: what type of file to output (default is png)
returns:
outfile: full path to the created plot
"""
outfile = str()
if outputfilename is None:
print('Must specify a filename to save the plot to.')
sys.exit(1)
else:
outfile = outputfilename + '.' + outputfiletype
indv = pd.read_csv(csvfile)
indv['spend'] = indv['spend'].str.replace(re.compile(",|\$"), "").astype(float)
indv.groupby('person')['spend'].sum().sort_values(ascending=False).head(20).plot(kind='bar')
plt.savefig(outfile, bbox_inches='tight')
return outfile
def org_spend_plot(csvfile=None, outputfilename=None, outputfiletype="png"):
"""
creates a plot for org-based spends
args:
csvfile: full path to the CSV file
outputfilename: name (without extension) of the outputted plot
outputfiletype: what type of file to output (default is png)
returns:
outfile: full path to the created plot
"""
outfile = str()
if outputfilename is None:
print('Must specify a filename to save the plot to.')
sys.exit(1)
else:
outfile = outputfilename + '.' + outputfiletype
proj = pd.read_csv(csvfile)
proj['spend'] = proj['spend'].str.replace(re.compile(",|\$"), "").astype(float)
proj.groupby('project')['spend'].sum().sort_values(ascending=False).head(20).plot(kind='bar')
plt.savefig(outfile, bbox_inches='tight')
return outfile