-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.py
More file actions
156 lines (126 loc) · 3.68 KB
/
command.py
File metadata and controls
156 lines (126 loc) · 3.68 KB
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
# -*- coding: utf-8 -*-
"""
Created on Thu Apr 4 10:00:47 2019
@author: piyus
"""
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import sys
def totuple(a):
try:
return tuple(totuple(i) for i in a)
except TypeError:
return a
def main():
file="cereal_breakfast.csv"
dataset=pd.read_csv("cereal_breakfast.csv")
program_name = sys.argv[0]
arguments = sys.argv[1:]
count = len(arguments)
X=[]
for x in sys.argv:
X.append(x)
ob=Barplot(X[1],X[2],X[3])
if X[4]=='bar':
ob.bar()
elif X[4]=='scatplot':
ob.scatplot()
elif X[4]=='plot':
ob.plot()
elif X[4]=='stackbar':
ob.stackbar()
elif X[4]=='stackplot':
ob.stackplot()
elif X[4]=='barh':
ob.barh()
class Barplot:
def __init__(self,file,x,y):
self.x = x
self.y = y
self.file = file
type(self.x)
type(self.y)
def plot(self):
data = pd.read_csv(self.file)
x = data[self.x]
y = data[self.y]
fig, ax = plt.subplots()
y_pos = np.arange(len(x))
ax.plot(x,y)
plt.xlabel(self.x)
plt.ylabel(self.y)
plt.xticks(y_pos, x, rotation=90)
plt.xlabel(self.x)
plt.ylabel(self.y)
ax.grid(True)
plt.show()
def bar(self):
data = pd.read_csv(self.file)
fig = plt.figure()
height = data[self.y]
bars = data[self.x]
plt.xlabel(self.x)
plt.ylabel(self.y)
y_pos = np.arange(len(bars))
plt.bar(y_pos, height)
plt.xticks(y_pos, bars, rotation=90)
plt.subplots_adjust(bottom=0.4, top=0.99)
fig.set_size_inches(18, 10.5)
plt.show()
def scatplot(self):
data = pd.read_csv(self.file)
bars = data[self.x]
height = data[self.y]
fig = plt.figure()
plt.scatter(bars,height,alpha=0.5)
plt.xlabel(self.x, rotation=90)
plt.ylabel(self.y)
plt.grid(True)
plt.xlabel(self.x)
plt.ylabel(self.y)
plt.xticks(y_pos, bars, rotation=90)
fig.set_size_inches(18, 10.5)
fig.savefig('C:/xampp/htdocs/Mini/n.png')
def stackbar(self):
width = 0.35
data = pd.read_csv(self.file)
x = data[self.x]
y = data[self.y]
x=np.array(x)
y=np.array(y)
plt.xlabel(self.x)
plt.ylabel(self.y)
N=len(x)
fig = plt.figure()
ind = np.arange(N)
x=totuple(x)
y=totuple(y)
p1=plt.bar(ind, x, width)
p2=plt.bar(ind,y, width,bottom=x)
plt.legend((p1[0], p2[0]), (self.x,self.y))
fig.savefig('C:/xampp/htdocs/Mini/n.png')
def stackplot(self):
data = pd.read_csv(self.file)
x = data[self.x]
y = data[self.y]
x=np.array(x)
plt.xlabel(self.x)
plt.ylabel(self.y)
y=np.array(y)
y = np.vstack([x,y])
fig, ax = plt.subplots()
ax.stackplot(x, y)
plt.show()
def barh(self):
data = pd.read_csv(self.file)
height = data[self.x]
bars = data[self.y]
plt.xlabel(self.x)
plt.ylabel(self.y)
y_pos = np.arange(len(bars))
plt.barh(y_pos, height)
plt.yticks(y_pos, bars)
plt.show()
if __name__ =="__main__":
main()