python - Matplotlib极坐标轮廓图:跨越theta原点连续
问题描述
我有格式E
( freq
, theta
) 的数据,其中E
是 2D 数组,freq
和theta
是 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')
解决方案
与此类似的东西: 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)
推荐阅读
- python - 解包类定义以在对象之间共享变量名
- c# - 使用 XML Serializer 和 TextWriter 将节点附加到 XML 根节点
- function - Scilab:我想绘制一个有两个变量的函数
- csv - awk FPAT 忽略 csv 中的逗号
- python - Pyqt5 QLabel,顶部是图像,底部是文本
- wpf - 如何以编程方式禁用 DatePicker?
- raspberry-pi - bitbake-layers add-layer meta-python meta-raspberrypi 失败
- javascript - Vimeo API 方法中的变量“未定义”
- javascript - 从数组中存在的所有子数组中获取所有元素而不从主数组中删除元素?
- vue.js - 对 djoser 身份验证的 POST 请求