generated from mwc/lab_scatter
	
		
			
				
	
	
		
			60 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			60 lines
		
	
	
		
			1.3 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):
 | 
						|
    lower_bound = minimum(data)
 | 
						|
    Upper_bound = maximum(data)
 | 
						|
    return [lower_bound, Upper_bound]
 | 
						|
    
 | 
						|
 | 
						|
def clamp(value, low, high):
 | 
						|
    if value < low:
 | 
						|
        return low 
 | 
						|
    if value > high:
 | 
						|
        return high 
 | 
						|
    else: 
 | 
						|
        return value
 | 
						|
 | 
						|
 | 
						|
 | 
						|
def ratio(value, start, end):
 | 
						|
    if start == end: 
 | 
						|
        return 0.0
 | 
						|
    clamped_value = clamp(value, start, end)
 | 
						|
    result = (clamped_value - start)/(end - start)
 | 
						|
    return result
 | 
						|
 | 
						|
def scale(value, domain_min, domain_max, range_min, range_max):
 | 
						|
    r = ratio(value, domain_min, domain_max)
 | 
						|
    scaled_value = range_min + r * (range_max - range_min)
 | 
						|
    return scaled_value
 | 
						|
 | 
						|
def get_x_values(points):
 | 
						|
    x_values = [point[0] for point in points]
 | 
						|
    return x_values
 | 
						|
 | 
						|
def get_y_values(points):
 | 
						|
    y_values = [point[1] for point in points]
 | 
						|
    return y_values
 |