-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.py
33 lines (30 loc) · 934 Bytes
/
utilities.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
import os
import sys
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
def load_points_from_file(filename):
"""Loads 2d points from a csv called filename
Args:
filename : Path to .csv file
Returns:
(xs, ys) where xs and ys are a numpy array of the co-ordinates.
"""
points = pd.read_csv(filename, header=None)
return points[0].values, points[1].values
def view_data_segments(xs, ys):
"""Visualises the input file with each segment plotted in a different colour.
Args:
xs : List/array-like of x co-ordinates.
ys : List/array-like of y co-ordinates.
Returns:
None
"""
assert len(xs) == len(ys)
assert len(xs) % 20 == 0
len_data = len(xs)
num_segments = len_data // 20
colour = np.concatenate([[i] * 20 for i in range(num_segments)])
plt.set_cmap('Dark2')
plt.scatter(xs, ys, c=colour)
plt.show()