2維變數中
在已知有限資料中,我們期許這些資料跟變數之間是連續的變化,我們可以利用函式griddata
輸入有限資料,藉由插分的方式,求出有限資料周為值,且運用pcolar, surf3D,建構出完整資料於區域內的分布。
以下例子是針對一片晶圓進行25點薄膜量測(左圖),藉由griddata處理後,在藉由pcolar呈現。
####Code####
import numpy as np
import math
import matplotlib.pyplot as plt
from scipy.interpolate import griddata
R=[0 ,33.3333,33.3333,33.3333,33.3333,
66.6667,66.6667,66.6667,66.6667,66.6667,66.6667,66.6667,66.6667,
100,100,100,100,100,100,100,100,100,100,100,100]
phi=[0,0,90,180,270,
0,45,90,135,180,225,270,315,
0,30,60,90,120,150,180,210,240,270,300,330]
tk=[177,172.49,172.68,173.4,171.12,
170.03,168.8,169.86,171.14,169.4,168.43,169.67,170.46,
170.01,166.21,167.35,168.66,168.23,170.53,168.99,171.06,175.79,170.84,171.25,174.4]
x=[]
y=[]
z=[]
for ii in range(0,len(R)):
x.append(R[ii]*np.cos(phi[ii]/57.3))
y.append(R[ii]*np.sin(phi[ii]/57.3))
z.append(tk[ii])
x_grid,y_grid=np.meshgrid(np.linspace(-100,100,100),np.linspace(-100,100,100))
Z=griddata((x,y),z,(x_grid,y_grid),method='cubic')
Zm=np.ma.masked_where(np.isnan(Z),Z)
print('x',x)
print('y',y)
print('z',z)
# print('x_grid',x_grid)
# print('y_grid',y_grid)
# print('x_grid',x_grid)
# print('y_grid',y_grid)
# print('Z',Z)
fig= plt.figure()
c=plt.pcolor(np.linspace(-100,100,100),np.linspace(-100,100,100),Zm)
plt.title('Thicnkness distribution')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.colorbar(c)
fig.savefig('test_scatter.png')
plt.show()
這邊要注意的是使用griddata前要先import
from scipy.interpolate import griddata
因為資料量測是由晶圓(圓形)求得,所以在使用griddate時會產些一些nan值,在pcolar是時無法處理nan值
需使用np.ma.masked_where(np.isnan(Z),Z) 處理資料(將nan 轉換為--)
才能將資料由pcolar 輸出。
留言列表