- 积分
 - 634
 
	- 贡献
 -  
 
	- 精华
 
	- 在线时间
 -  小时
 
	- 注册时间
 - 2015-4-21
 
	- 最后登录
 - 1970-1-1
 
 
 
 
 
 
 | 
	
 
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册 
 
 
 
x
 
想用计算出来的温度指数画北美地区的图,用这个代码画前几年都没问题,单画到这个年份就报错“bboxes can not be empty”,但是确认过这个区域的数据不会是0,所以想问问这个是什么问题呢?报错:2.6718372428853816Traceback (most recent call last): 
 
  File "/Users/untitled2.py", line 134, in <module> 
    cf = ax.contourf(lon,lat,md_values_plot,extend='both') 
 
  File "/Users/opt/anaconda3/lib/python3.7/site-packages/cartopy/mpl/geoaxes.py", line 1404, in contourf 
    for col in result.collections 
 
  File "/Users/opt/anaconda3/lib/python3.7/site-packages/matplotlib/transforms.py", line 701, in union 
    raise ValueError("'bboxes' cannot be empty") 
 
ValueError: 'bboxes' cannot be empty 
 - year_se = 1991
 
 - mon_se = 7
 
 - md_values_plot=np.nansum(md_values[(year==year_se)&(mon==mon_se),:,:],axis = 0)
 
 - md_values_plot = np.where(md_values_plot==0,np.nan,md_values_plot)
 
 - md_index=np.nanmax(md_values_plot)
 
 - print(md_index)
 
  
- proj = ccrs.PlateCarree()
 
 - fig = plt.figure(figsize=(4, 4), dpi=550)  # 创建画布
 
 - extent=[-130,-70,25,50]
 
 - ax = fig.subplots(1, 1, subplot_kw={'projection': proj})  # 创建子图
 
 - ax.set_extent(extent)
 
 - ax.add_feature(cfeature.LAND)####添加陆地######
 
 - ax.add_feature(cfeature.COASTLINE,lw=0.3)#####添加海岸线#########
 
 - ax.add_feature(cfeature.RIVERS,lw=0.25)#####添加河流######
 
 - ax.add_feature(cfeature.LAKES)######添加湖泊#####
 
 - ax.add_feature(cfeature.BORDERS, linestyle='-',lw=0.25)####不推荐,我国丢失了藏南、台湾等领土############
 
 - ax.add_feature(cfeature.OCEAN)######添加海洋########
 
 - ax.add_feature(cfeature.OCEAN.with_scale('10m'))
 
 - ax.add_feature(cfeature.LAND.with_scale('10m'))
 
 - ax.add_feature(cfeature.RIVERS.with_scale('10m'),lw=0.6)
 
 - ax.add_feature(cfeature.LAKES.with_scale('10m'))
 
 - ax.add_feature(cfeature.BORDERS.with_scale('50m'), linestyle='-',lw=0.6)
 
 - ax.add_feature(cfeature.COASTLINE.with_scale('10m'),lw=0.5)
 
 - gl = ax.gridlines(crs=ccrs.PlateCarree(), draw_labels=True, linewidth=0.2, color='k', alpha=0.5, linestyle='--')
 
 - gl.xlabels_top = False ##关闭上侧坐标显示
 
 - gl.ylabels_right = False ##关闭右侧坐标显示
 
 - gl.xlabel_style={'size':5}
 
 - gl.ylabel_style={'size':5}
 
 - gl.xformatter = LONGITUDE_FORMATTER ##坐标刻度转换为经纬度样式
 
 - gl.yformatter = LATITUDE_FORMATTER
 
 - gl.xlocator = mticker.FixedLocator(np.arange(extent[0], extent[1]+0.1, 5))
 
 - gl.ylocator = mticker.FixedLocator(np.arange(extent[2], extent[3]+0.1, 5))
 
 - #plot
 
  
 
- Colors = ('#FFFFFF','#C0C0C0','#696969','#FFD700','#FF6347','#FF0000','#A0522D','#8B0000')
 
 - cf = ax.contourf(lon,lat,md_values_plot,extend='both')
 
 - cbar=plt.colorbar(cf,ax=ax,orientation='horizontal',pad=0.15,shrink=1)
 
 - cbar.ax.tick_params(labelsize=8)
 
 - cbar.set_label('HWMId',fontdict={'size':12})
 
  
- cbar.ax.set_title('West U.S 1991 July')
 
 - plt.show()
 
  复制代码 
 
 
 |   
 
 
 
 |