-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscatter_plot.py
64 lines (52 loc) · 1.65 KB
/
scatter_plot.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
import srcs.ml_toolkit as ml
import pandas as pd
import sys
import matplotlib
import matplotlib.pyplot as plt
from argparse import ArgumentParser
matplotlib.use('TkAgg')
def main():
filename = 'datasets/dataset_train.csv'
try:
ml.check_file(filename)
except AssertionError as e:
print(e)
sys.exit(1)
parser = ArgumentParser()
parser.add_argument('--c1',
type=str,
default='Astronomy',
help='First course to compare')
parser.add_argument('--c2',
type=str,
default='Defense Against the Dark Arts',
help='Second course to compare')
args = parser.parse_args()
df = pd.read_csv(filename)
df = ml.drop_columns_by_name(df, ['Index', 'First Name', 'Last Name',
'Birthday', 'Best Hand'])
try:
df[args.c1]
df[args.c2]
except KeyError as e:
print(f'KeyError: {e}\nValid columns are:')
for col in df.columns:
print(f' -{col}')
sys.exit(1)
colors = {
'Slytherin': 'green',
'Gryffindor': 'red',
'Ravenclaw': 'blue',
'Hufflepuff': 'yellow'
}
for house, color in colors.items():
plt.scatter(df[df['Hogwarts House'] == house][args.c1],
df[df['Hogwarts House'] == house][args.c2],
alpha=0.5, label=house, color=color)
plt.xlabel(args.c1)
plt.ylabel(args.c2)
plt.legend(loc='upper right')
plt.title(f'{args.c1} vs {args.c2}')
plt.show()
if __name__ == '__main__':
main()