Python polar 2d data
import numpy as np
from scipy.interpolate import griddata
import matplotlib.pyplot as plt
import pdb
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)
plt.show()
pdb.set_trace()