基于K210
折线图和散点图
def draw_data_to_wave(img , data , start_x, start_y, w , h , color = (255,255,255),fill = True):
#计算数据的长度
data_len = len(data)
#获取数据限极限幅值
data_min , data_max = min(data) , max(data)
if data_min == data_max:
img.draw_line(start_x,start_y,start_x+w,start_y,color)
return
#数据归一化系数
arg_data_high = h / (data_max-data_min)
#坐标变换系数
arg_x = w / data_len
#设置初始的上一次的值
one_data = data[0]
one_data = one_data - data_min
draw_data = int(one_data * arg_data_high)
last_x = start_x
last_value = start_y - int( draw_data )
#遍历每一个数据,单点进行变换
for i in range(data_len):
#获取当前点数据
one_data = data[i]
one_data = one_data - data_min
#数据高度归一化
draw_data = int(one_data * arg_data_high)
#计算实际起始x坐标
x = start_x + int( i * arg_x )
y = start_y - int( draw_data )
#设置对应点
if fill:
img.draw_line(last_x,last_value,x,y,color)
#记录上一次的值
last_value = y
last_x = x
else:
img