-
Notifications
You must be signed in to change notification settings - Fork 0
/
pair_plot.py
60 lines (50 loc) · 1.65 KB
/
pair_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
import sys
import matplotlib.pyplot as plt
from preprocessing import load_data
from histogram import to_histogram
from scatter_plot import to_scatter
def main():
""" Plots scatter plots for the grade repartition between two features,
for each feature in the dataset, separated by house.
"""
try:
if len(sys.argv) != 2:
raise IndexError('Please enter one argument.')
df, features = load_data(sys.argv[1])
features_len = len(features)
_, axes = plt.subplots(
nrows=features_len,
ncols=features_len,
)
for i, ax_row in enumerate(axes):
for j, cell in enumerate(ax_row):
cell.set_xticks([])
cell.set_yticks([])
cell.set_xlabel(
'\n'.join(features[j].split()),
fontsize=7
)
cell.set_ylabel(
'\n'.join(features[i].split()),
fontsize=7
)
if i != j:
to_scatter(
df=df,
x_feature=features[i],
y_feature=features[j],
ax=cell
)
else:
to_histogram(
df=df,
feature=features[i],
ax=cell
)
for ax in axes.flat: # Remove the labels in the middle of the plot
ax.label_outer()
plt.show()
except BaseException as e:
print(type(e).__name__, ':', e)
if __name__ == '__main__':
main()