参考:气象学家公众号
加入个人补充或总结
fig=plt.figure(figsize=(7,4),dpi=200)
ax1=fig.add_subplot(111)
ax2=ax1.twinx()
line2,=ax2.plot(times,pressures,'k-',lw=1.2,label='气压')
plt.show()
fig,((ax1),(ax2))=plt.subplots(2,1,figsize=(5,5),dpi=200,sharex='all') #sharex='all'命令,这是令两幅子图共享x轴
fig.subplots_adjust(hspace=0) # 上下间距等于0
plt.show()
nc数据存储格点问题导致0°或者180°出现空白情况,解决方法:
from cartopy.util import add_cyclic_point
cycle_sst, cycle_lon = add_cyclic_point(sst, coord=lon)
cycle_LON, cycle_LAT = np.meshgrid(cycle_lon, lat)
ax.contourf(cycle_LON, cycle_LAT, cycle_sst,levels=np.arange(-10,35),cmap='RdBu_r')
直接使用plt.barbs(lon,lat,u,v,zorder=5)会出现问题,因为关于风羽的风速,ax.barbs()中当风速在**(0,2.5)时,认为无风画一圆圈,在(2.5,7.5)**为一短杆,因此需改成
plt.barbs(lon,lat,u,v,barb_increments={'half':2,'full':4,'flag':20},zorder=1) # zorder图层上下叠放位置,值越大越在上层
barb_increments={‘half’:2,‘full’:4,‘flag’:20},修改风矢杆长短杆线和三角分别代表的风速大小。注意:单位与u v数据一致,(0,1)认为无风画⚪,(1,3)一短杆,(3,5)一长杆。
国外:长杆代表风向,短杆代表风速,每个短杆为10knots,如果是半个短杆,则为5knots(1knot=1节=0.514m/s)
国内:长杆代表风向,短杆代表风速,每个短杆为4m/s,如果是半个短杆,则为2m/s。(1m/s=1.94knots)
在将cartopy官网例子本土化的过程中,matplotlib的marker中没有现成的台风符号,解决方案:
方案一:通过数字6和9的叠加来产生台风符号
ax.scatter(x,y2,s=200,marker='$6$',color='crimson')
ax.scatter(x,y3,s=200,marker='$9$',color='crimson')
方案二:通过自定义台风符号来绘制
def get_hurricane():
u = np.array([ [2.444,7.553],
[0.513,7.046],
[-1.243,5.433],
[-2.353,2.975],
[-2.578,0.092],
[-2.075,-1.795],
[-0.336,-2.870],
[2.609,-2.016] ])
u[:,0] -= 0.098
codes = [1] + [2]*(len(u)-2) + [2]
u = np.append(u, -u[::-1], axis=0)
codes += codes
return mpath.Path(3*u, codes, closed=False)
hurricane = get_hurricane()
ax.scatter(x,y1, s=350, marker=hurricane,
edgecolors="crimson", facecolors='none', linewidth=3)
参数 | 介绍 |
---|---|
ax | 代表需要传入色条的ax |
shrink | 色条相对长度 |
orientation=‘horizontal’ | 代表色条横向还是竖向,vertical代表垂直;horizontal代表水平 |
cax | 色条绝对位置 |
pad | 色条和子图ax之间距离 |
extend = ‘neither’ | 色条两头是否为尖,默认neither。both表示两头尖,min表示数值小的那头尖,max表示数值大的那头尖 |
ticks | 默认根据你的ax里的间距大小自动分配,可以用列表自定义间距 |
format | 控制刻度样式,如‘%.3f’表示保留三位小数 |