generated from mwc/lab_scatter
51 lines
1.2 KiB
Python
51 lines
1.2 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 = None
|
|
for number in data:
|
|
if highest is None:
|
|
highest = number
|
|
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 maximum([low, minimum([value, high])])
|
|
|
|
def ratio(value, start, end):
|
|
unclamped_ratio=(value-start)/(end-start)
|
|
return clamp(unclamped_ratio, 0.0, 1.0)
|
|
|
|
def scale(value, domain_min, domain_max, range_min, range_max):
|
|
scale_ratio=ratio(value, domain_min, domain_max)
|
|
range_length = range_max - range_min
|
|
return range_min + scale_ratio * range_length
|
|
|
|
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
|