相关内容在李开元、豆京华的《气Py:Python气象资料处理与可视化中》有处理方法,但由于matlplotlib不同版本时需要更多操作,再次记录下完整的修改过程。
(1)首先需要修改quiver.py文件:
matplotlib 设计上对于不足半个风羽 half,也就是 2m/s 的风场不做绘制或以空心圆替代,但是同时该点的风向信息就被消隐了。可以通过修改matplotlib 自带的 barbs 方法,将风场的风向表示出来。需要按照修改 Anaconda3\Lib\site-packages\matplotlib\下的quiver.py,在 if half barb[index1:条件后加入同级别的判断语块--
if empty_flag[index] and u[index] != 0 and v[index] != 0:
if offset == length:
poly_verts.append((endx, endy + offset))
offset -= 1.5*spacing
poly_verts.extend( [(endx, endy + offset),
(endx + full_height / 200, endy + offset + full_width /40),
(endx, endy + offset)])
(2)在新版本matplotlib还需要注释相关信息:
3.4.3版本(可能及以上)的matplotlib还需要注释掉for index, angle in np.ndenumerate(angles):下面的第一个if块即可
# If the vector magnitude is too weak to draw anything, plot an
# empty circle instead
#if empty_flag[index]:
# We can skip the transform since the circle has no preferred
# orientation
# barb_list.append(empty_barb)
# continue
也可以参考气象家园帖子相关讨论:
求助如何在python中风羽图当风速小于2m/s时需显示风向(风杆)-编程作图-气象家园_气象人自己的家园 (06climate.com)