generated from mwc/lab_scatter
50 lines
1.1 KiB
Python
50 lines
1.1 KiB
Python
# transform.py
|
|
# ------------
|
|
# By MWC Contributors
|
|
# The functions in this module transform data.
|
|
# None of them are finished; this is your job!
|
|
|
|
def maximum(data):
|
|
highest = data[0]
|
|
for number in data:
|
|
if number > highest:
|
|
highest = number
|
|
return highest
|
|
|
|
def minimum(data):
|
|
lowest = None
|
|
for number in data:
|
|
if lowest is None:
|
|
lowest = number
|
|
if number < lowest:
|
|
lowest = number
|
|
return lowest
|
|
|
|
def bounds(data):
|
|
return [minimum(data), maximum(data)]
|
|
|
|
|
|
def clamp(value, low, high):
|
|
return max(low, min(value, high))
|
|
|
|
|
|
def ratio(value, start, end):
|
|
r = (value - start)/(end - start)
|
|
return clamp(r,0,1)
|
|
|
|
def scale(value, domain_min, domain_max, range_min, range_max):
|
|
r = ratio(value, domain_min, domain_max)
|
|
return range_min + r * (range_max - range_min)
|
|
|
|
|
|
def get_x_values(points):
|
|
x_values = []
|
|
for x, y in points:
|
|
x_values.append(x)
|
|
return x_values
|
|
|
|
def get_y_values(points):
|
|
y_values = []
|
|
for x, y in points:
|
|
y_values.append(y)
|
|
return y_values |