前几期,有朋友让我用python将cp的测试数据转化为map
但是,他又想把特定的测量数据转化为map图后,进行上色,即不同的测试数据能够呈现不同的颜色,以便于直观的观察其趋势。
数据样式:
左边列是序号,中间列是xy,x-0016y0079表示的是(x,y)坐标为(16,79),最右行是测试数据。序号最大值为13278,即这个wafer有13278粒完成测试,得到了cp的测试数据。
我的思路:
1,将现有数据按照坐标,转化为map图,并将测试数值一一对应填入map图中。
2,有时测试标准是不一样的,所以可以手动设置标准值,这个在运行程序时能够弹出对话框,让使用者能够随意更改标准。低于标准值的测量值单元格呈现浅红色到红色的渐变,高于标准值的测量值呈现浅绿到紫色的渐变。
做出的效果:
1,双击“map上色.exe”运行程序
2,选择要上色的测试数据文件
3,手动设置标准值
4,设置文件名
5,在原文件地址下输出包含map图的文件
6,打开文件
这样就很直观地看出测量值的分布图来了。
原代码如下,欢迎参考:
import pandas as pdimport numpy as npimport matplotlib.pyplot as pltfrom openpyxl import workbookfrom openpyxl.utils.dataframe import dataframe_to_rowsfrom openpyxl.styles import patternfillfrom tkinter.simpledialog import askfloatfrom tkinter import tkfrom tkinter import filedialogimport colorsysfrom tkinter.simpledialog import askstringdef get_threshold(threshold_type): print(fgetting threshold for {threshold_type}...) root = tk() root.withdraw() if threshold_type == il: threshold = askfloat(finput {threshold_type} threshold, fenter the {threshold_type} threshold:) return threshold elif threshold_type == fc: threshold_range_str = askstring(finput {threshold_type} threshold range, fenter the {threshold_type} threshold range (e.g., 'min,max'):) print(fuser input for fc threshold: {threshold_range_str}) try: min_threshold, max_threshold = map(float, threshold_range_str.split(',')) return min_threshold, max_threshold except valueerror: print(invalid input. please enter two numbers separated by a comma.) return none root.destroy()def color_map(value, threshold, data_min, data_max): # 正常化值到 [threshold, data_max] 区间,从极淡绿(144,238,144)到紫(128,0,128) if threshold <= value <= data_max: normed_value = (value - threshold) / (data_max - threshold) r = int(144 * (1 - normed_value) + 128 * normed_value) g = int(238 * (1 - normed_value) + 0 * normed_value) b = int(144 * (1 - normed_value) + 128 * normed_value) # 正常化值到 [data_min, threshold] 区间,从红(255,0,0)到黄(255,255,0) elif -10 <= value < threshold: normed_value = (value + 10) / (threshold + 10) # 正则化到 [0, 1] 区间 r = int(222 + (241 - 222) * normed_value) # 从 222 渐变到 241 g = int(28 + (147 - 28) * normed_value) # 从 28 渐变到 147 b = int(49 + (156 - 49) * normed_value) # 从 49 渐变到 156 elif data_min <= value < -10: r, g, b = 139, 0, 0 else: r, g, b = 255, 255, 255 # 默认为白色 hex_color = 'ff' + '{:02x}{:02x}{:02x}'.format(r, g, b) return hex_colordef fc_color_map(value, min_threshold, max_threshold, data_min, data_max): if min_threshold <= value max_threshold or value < min_threshold: r, g, b = 139, 0, 0 hex_color = 'ff' + '{:02x}{:02x}{:02x}'.format(r, g, b) else: r, g, b = 255, 255, 255 # default to white hex_color = 'ff' + '{:02x}{:02x}{:02x}'.format(r, g, b) return hex_colordef save_to_excel(df, threshold, output_path, color_function): wb = workbook() ws = wb.active data_min = df.min().min() # 获取整个 dataframe 中的最小值 data_max = df.max().max() # 获取整个 dataframe 中的最大值 for i in range(df.shape[0]): for j in range(df.shape[1]): value = df.iloc[i, j] if not pd.isna(value): cell = ws.cell(row=i + 2, column=j + 2) cell.value = value # 选择正确的颜色映射函数和参数 if color_function == color_map: fill_color = color_function(value, threshold, data_min, data_max) elif color_function == fc_color_map: min_threshold, max_threshold = threshold # 从元组中解包 fill_color = color_function(value, min_threshold, max_threshold, data_min, data_max) cell.fill = patternfill(start_color=fill_color, end_color=fill_color, fill_type=solid) wb.save(output_path)def rgb_to_hex(rgb): return '{:02x}{:02x}{:02x}'.format(rgb[0], rgb[1], rgb[2])def main(): print(starting main function...) input_file = filedialog.askopenfilename(title=select the csv file) print(fselected file: {input_file}) if il in input_file.lower(): threshold_type = il color_function = color_map threshold = get_threshold(threshold_type) else: threshold_type = fc color_function = fc_color_map threshold = get_threshold(threshold_type) if threshold is none: print(invalid threshold. exiting program.) return output_file = filedialog.asksaveasfilename(title=save the visualization as, defaultextension=.xlsx, filetypes=[(excel files, *.xlsx)]) print(foutput file: {output_file}) df = pd.read_csv(input_file) save_to_excel(df, threshold, output_file, color_function)if __name__ == __main__:
main()
2018年第三季度全球智能手机出货量达到3.868亿台
双十二蓝牙耳机买哪款好?降噪效果好的蓝牙耳机推荐
日本首次批准了向韩国出口EUV光刻胶
区块链开发金融交易平台
我们怎样迎接5G带来的新生活
如何用python对生成的map图进行上色呢?
2021年国内智能手机所需AP出货将为7亿9,570万颗
二手手机江湖往事:苹果一跺脚,华强北抖三抖
PCle第五代CEM连接器
如何使用Arduino制作电感LC表
EFM8 Universal Bee试用体验:开箱+上电
传魅族将接入华为HMS Core 高通发布骁龙860
火爆新能源行业的CTC技术 或将颠覆光纤激光器行业?
三星Exynos瞄准中低端市场 联发科布局倍感压力
思瑞浦是少数实现通信系统模拟芯片技术突破的本土企业之一
三防AGM2,户外出游手机的不二之选!
2020世界VR产业大会云峰会在南昌隆重召开
威纶通MT607触摸屏的初步认识
广电总局重申181号文件,互联网电视路在何方?
5G要用毫米波需要克服的两大难题