wrote all of the functions in transform.py to make a scatter plot.

This commit is contained in:
kated
2026-03-18 11:11:43 -04:00
parent 2cd1275b84
commit 76ab4b547f

View File

@@ -28,7 +28,7 @@ def bounds(data):
"Returns a list of the smallest and largest numbers in data" "Returns a list of the smallest and largest numbers in data"
lowest = minimum(data) lowest = minimum(data)
highest = maximum(data) highest = maximum(data)
boundary = [minimum, maximum] boundary = [lowest, highest]
return boundary return boundary
def clamp(value, low, high): def clamp(value, low, high):
@@ -51,13 +51,14 @@ def ratio(value, start, end):
numerator = value - start numerator = value - start
denominator = end - start denominator = end - start
ratio = numerator / denominator ratio = numerator / denominator
final_ratio = clamp(ratio, 0.0, 1.0) r = clamp(ratio, 0.0, 1.0)
return final_ratio return r
def scale(value, domain_min, domain_max, range_min, range_max): def scale(value, domain_min, domain_max, range_min, range_max):
"Given a value within a domain, returns the scaled equivalent within range." "Given a value within a domain, returns the scaled equivalent within range."
ratio_d = ratio(value, domain_min, domain_max) r = ratio(value, domain_min, domain_max)
ratio_r = ratio(value, range_min, range_max) scaled_value = range_min + r * (range_max - range_min)
return scaled_value
def get_x_values(points): def get_x_values(points):
"Returns the first value for each point in points." "Returns the first value for each point in points."
@@ -71,6 +72,6 @@ def get_y_values(points):
"Returns the second value for each point in points." "Returns the second value for each point in points."
y_list = [] y_list = []
for i in points: for i in points:
y_value = i[0] y_value = i[1]
y_list.append(y_value) y_list.append(y_value)
return y_list return y_list