我想绘制一张从XYZ数据获得的方位角和天顶角的极坐标图。但是我传递给contourf函数的数组是畸形的,我不知道如何纠正这个问题?在
import numpy as np
import matplotlib.pyplot as plt
# Populated arrays with angles.
azimuths = np.random.random(200)*360
zeniths = np.random.random(200)*180
a_bins = np.linspace(0,360,13)
z_bins = np.linspace(0,180,7)
grid, ae, ze = np.histogram2d(azimuths, zeniths, bins=[a_bins,z_bins])
a_bins = np.radians(a_bins)
r, theta = np.meshgrid(z_bins, a_bins)
# Plot
fig, ax = plt.subplots(subplot_kw=dict(projection='polar'))
cax = ax.contourf(theta, r, grid, 30)
cb = fig.colorbar(cax)
plt.show()
代码运行,但抛出以下警告:x的形状与z的形状不匹配:找到(13,7)而不是(12,6)。
现在我想我理解了这个错误。方位角为13个(0-360),7个为天顶(0-180)。histogram2d函数返回的矩阵的形状为(12,6),因为这是边之间的槽数。我只是不知道怎么修理箱子。在
一种方法是将}相同的形状。这是必要的,这样极坐标图就可以一直延伸(并且在
grid
数组展开为与theta
和{theta=0
处匹配)。在相关问题 更多 >
编程相关推荐