Matplotlib极地轮廓线图:在theta原点连续

时间:2019-01-15 23:15:48

标签: python matplotlib plot polar-coordinates contourf

我有Efreqtheta)格式的数据,其中E是2D数组,freqtheta是一维阵列。

下面的代码部分产生了附图。但是,我想使等高线图在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')

生成的图: Directional wave spectrum

1 个答案:

答案 0 :(得分:0)

类似于以下内容: https://stackoverflow.com/a/22129714/9324652

enter image description here

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