对于气象专业的小学生来说,风场是预报重要的参考数据,我们所知的风羽有四种:短线代表风速2m/s,长线代表风速4m/s,空心三角代表风速20m/s,实心三角代表风速50m/s。而matplotlib的风羽只有短线、长线、三角三种,而这里的三角不分空心实心,但是可通过改变风羽颜色为白色使三角变为空心形状,虽然这三种可以自定义各自代表的风速,但是仍与我们的使用****惯不符,即使把三角设成20m/s,原本一个实心三角就能表示的50m/s的风在matplotlib中需要两个三角外加两条长线一条短线。为了迎合预报员的需求,我在研究了matplotlib的风场函数barbs(),,使得matplotlib也有了空心三角和实心三角之分。一、函数barbs的使用barb(X,Y,U,V,,**kw)X:风场数据X坐标Y:风场数据Y坐标U:风的水平方向分量V:风的垂直方向分量'''Demonstrationofwindbarbplots'''=(-5,5,5)X,Y=(x,x)U,V=12*X,12*Ydata=[(-,.5,-6,-6),(1,-1,-46,46),(-3,-1,11,-11),(1,,80,80),(,,25,15),(-,-,-5,40)]data=(data,dtype=[('x',),('y',),('u',),('v',)])#Defaultparameters,uniformgridax=(2,2,1)(X,Y,U,V)#Arbitrarysetofvectors,makethemlongerandchangethepivotpoint#(pointaroundwhichthey'rerotated)tobethemiddleax=(2,2,2)(data['x'],data['y'],data['u'],data['v'],length=8,pivot='middle')#,#don'troundthevalues,andchangesomeofthesizeparametersax=(2,2,3)(X,Y,U,V,(U*U+V*V),fill_empty=True,rounding=False,sizes=dict(emptybarb=,spacing=,height=))#Changecolorsaswellastheincrementsforpartsofthebarbsax=(2,2,4)(data['x'],data['y'],data['u'],data['v'],flagcolor='r',barbcolor=['b','g'],barb_increments=dict(half=10,full=20,flag=100),flip_barb=True)()二、()classBarbs():***@(self,ax,*args,**kw):'...'def_find_tails(self,mag,rounding=True,half=5,full=10,flag=50):'...'def_make_barbs(self,u,v,nflags,nbarbs,half_barb,empty_flag,length,pivot,sizes,fill_empty,flip):'...'defset_UVC(self,U,V,C=None):'...'defset_offsets(self,xy):'...'通过读源代码可知类Barbs有五个方法分别为__init__、_find_tails、_make_barbs、set_UVC、set_offsets。***@(self,ax,*args,**kw):"""Theconstructortakesonerequire
Python自学笔记——Matplotlib风羽自定义 来自淘豆网www.taodocs.com转载请标明出处.