Python中二维曲面极坐标图的问题

2024-04-25 20:27:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图复制这个2D表面极坐标图(它是晶圆的厚度分布):

enter image description here

这是我的代码(包括数据):

import numpy as np
from scipy.interpolate import griddata
import matplotlib.pyplot as plt

x_pos = np.array([  0.   ,  11.748,   0.   , -11.748,   0.   ,  21.705,  21.705,
         8.988,  -8.988, -21.705, -21.705,  -8.988,   8.988,  35.245,
        30.517,  17.623,   0.   , -17.623, -30.517, -35.245, -30.517,
       -17.623,   0.   ,  17.623,  30.517,  46.098,  46.098,  39.078,
        26.111,   9.164,  -9.164, -26.111, -39.078, -46.098, -46.098,
       -39.078, -26.111,  -9.164,   9.164,  26.111,  39.078])
y_pos = np.array([  0.   ,   0.   ,  11.748,   0.   , -11.748,  -8.988,   8.988,
        21.705,  21.705,   8.988,  -8.988, -21.705, -21.705,   0.   ,
        17.623,  30.517,  35.245,  30.517,  17.623,   0.   , -17.623,
       -30.517, -35.245, -30.517, -17.623,  -9.164,   9.164,  26.111,
        39.078,  46.098,  46.098,  39.078,  26.111,   9.164,  -9.164,
       -26.111, -39.078, -44.29 , -44.29 , -39.078, -26.111])
values = np.array([721.0099, 679.8029, 708.8115, 687.4061, 682.9654, 593.4934,
       614.5019, 605.3102, 600.0777, 588.2717, 580.5319, 584.1863,
       598.9501, 584.5857, 565.1545, 588.9718, 570.4216, 553.165 ,
       540.6561, 555.0057, 533.8918, 552.6648, 567.4707, 590.8452,
       574.8677, 530.336 , 556.7502, 562.9214, 598.5813, 616.5076,
       620.0647, 612.7661, 600.2197, 541.4696, 510.0406, 531.339 ,
       509.6992, 540.1819, 539.2797, 493.9553, 514.0744])

# Making the contour plot

# CONVERTING TO Polar Coordinates
def cart2pol(x, y):
    r = np.sqrt(x**2 + y**2)
    theta = np.arctan2(y, x)
    return(r, theta)

r, theta = cart2pol(x_pos, y_pos)

r_grid=np.linspace(0,50,50)
theta_grid=np.linspace(-np.pi,np.pi,50)
r_matrix, theta_matrix = np.meshgrid(r_grid,theta_grid)

# Interpolate onto polar grid
values_grid_interp = griddata((r, theta), values, (r_matrix,theta_matrix),method='linear')

# #-- Plot... ------------------------------------------------
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
ax.contourf(theta_grid, r_grid, values_grid_interp)

我得到的是:

enter image description here

正如你所看到的,它完全不符合最初的情节,但我很难看出我做错了什么


Tags: posimportasnppipltarraymatrix