爱气象,爱气象家园! 

气象家园

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博登陆

只需一步, 快速开始

搜索
查看: 6819|回复: 1

python cartopy的画图问题

[复制链接]

新浪微博达人勋

发表于 2020-10-28 20:24:35 | 显示全部楼层 |阅读模式
Python
系统平台:
问题截图: -
问题概况: python cartopy画SSTA图中,该怎么进行坐标转换?
我看过提问的智慧: 没看过(看完再来提问)
自己思考时长(天): 1

登录后查看更多精彩内容~

您需要 登录 才可以下载或查看,没有帐号?立即注册 新浪微博登陆

x
本人刚刚学习cartopy不太明白怎么将数据集中的坐标,映射到我画的底图上?
我练习了一下2016SSTA的图,代码如下:
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import matplotlib.pyplot as plt
import cartopy.mpl.ticker as cticker
import xarray as xr
import numpy as np

f=xr.open_dataset('precip.mon.mean.nc')
precip=f['precip']
precip_avg_ds=precip.loc['1979-01-01':'2009-01-01']
precip_avg=np.nanmean(precip_avg_ds,0)
precip_2016=precip.loc['2016-07-01']

precip_2016a=precip_2016-precip_avg

lat=f['lat_bnds']
lon=f['lon_bnds']

#===画图
fig = plt.figure(figsize=(12,8))
ax = fig.add_subplot(1,1,1,projection = ccrs.PlateCarree(central_longitude=180))
ax.set_extent([0,360,-90,90], crs=ccrs.PlateCarree())
ax.add_feature(cfeature.COASTLINE.with_scale('50m'))
ax.set_xticks(np.arange(0,360+30,144), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-90,90+30,72), crs=ccrs.PlateCarree())

lon_formatter = cticker.LongitudeFormatter()
lat_formatter = cticker.LatitudeFormatter()
ax.xaxis.set_major_formatter(lon_formatter)
ax.yaxis.set_major_formatter(lat_formatter)
ax.set_title('2016aSSTA',loc='center',fontsize=18)
ax.set_title('unit: dagc',loc='right',fontsize=18)

cp=ax.contourf(lon,lat,precip_2016a,transform=ccrs.PlateCarree(),cmap='jet')
plt.colorbar(cp)


=====error=====
F:\anaconda\lib\site-packages\cartopy\mpl\geoaxes.py:704: UserWarning: Attempting to set identical left==right resultsin singular transformations; automatically expanding.left=-180.0, right=-180.0  self.set_xlim([x1, x2])TypeError: Shape of x does not match that of z: found (144, 2) instead of (72, 144)

请大神看看哪里错了?
密码修改失败请联系微信:mofangbao

新浪微博达人勋

发表于 2020-10-28 22:08:54 | 显示全部楼层
ax.set_xticks(np.arange(0,360+30,144), crs=ccrs.PlateCarree())
ax.set_yticks(np.arange(-90,90+30,72), crs=ccrs.PlateCarree())
亲,你想干嘛呢这是
密码修改失败请联系微信:mofangbao
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册 新浪微博登陆

本版积分规则

Copyright ©2011-2014 bbs.06climate.com All Rights Reserved.  Powered by Discuz! (京ICP-10201084)

本站信息均由会员发表,不代表气象家园立场,禁止在本站发表与国家法律相抵触言论

快速回复 返回顶部 返回列表