首页 > 解决方案 > Matplotlib极坐标轮廓图:跨越theta原点连续

问题描述

我有格式E( freq, theta) 的数据,其中E是 2D 数组,freqtheta是 1D 数组。

以下代码部分生成附图。但是,我想让轮廓图在 0 度原点上连续(即沿 0 方位角没有楔形空白)。

我已经探索了 matplotlib 文档,并非常广泛地发布了问题,但似乎无法找到解决此问题的方法。有任何想法吗?

代码:

[r, th] = np.meshgrid(freq,theta)

fig = plt.figure()
ax = fig.add_subplot(111, polar=True)
ax.set_theta_zero_location('N')
ax.set_theta_direction(-1)

cntf = ax.contourf(th,r,np.log10(E),cmap='jet',extend='both',
    levels=np.linspace(np.mean(np.log10(E)), np.amax(np.log10(E)), 15))

ax.set_rlim(0, .3)
label_position=ax.get_rlabel_position()
ax.text(np.radians(label_position+25),ax.get_rmax()/1.5,'f (Hz)',
        rotation=label_position,ha='center',va='center')

产生的情节: 定向波谱

标签: pythonmatplotlibplotpolar-coordinatescontourf

解决方案


与此类似的东西: https ://stackoverflow.com/a/22129714/9324652

在此处输入图像描述

dtheta = np.diff(theta).mean()
wrp_theta = np.concatenate((theta, theta[-1:] + dtheta))
wrp_E = np.concatenate((E, E[0:1, :]), axis=0)

推荐阅读