Cartopy 0.20 最新功能 —— Cartopy 装不上别慌,内附解决方案
生活随笔
收集整理的這篇文章主要介紹了
Cartopy 0.20 最新功能 —— Cartopy 装不上别慌,内附解决方案
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Cartopy 0.20 最新功能
背景介紹
Cartopy 是英國氣象局開發的地圖繪圖包,實現了 Basemap 的大部分功能,利用了強大的PROJ.4、NumPy和Shapely庫,并在Matplotlib之上構建了一個編程接口,用于創建發布質量的地圖,并進行地理空間數據處理與空間數據分析,對于地圖學與地理信息系統、大氣科學專業非常受用。
雖然,
- Cartopy的安裝依賴較為復雜,推薦使用conda install cartopy進行安裝,但很多同學可能因為安裝就從入門到放棄了qaq。
- 低版本的Cartopy(0.18及以下)功能仍然比較有限,對于非等經緯度的投影不能進行標注等細節問題。
但是,
- ModelWhale提供了氣象數據分析鏡像,免去了環境配置和模塊安裝的困擾,提供了常用的Python模塊,不定期進行維護和更新
- 最新基于Python3.9版本鏡像中包含Cartopy 0.20模塊,集成了很多新功能,并且更加穩定和友好
新功能介紹
網址:https://scitools.org.uk/cartopy/docs/latest/whatsnew/v0.20.html
新功能展示
1.支持六邊形圖(Hexbin)
fig = plt.figure(figsize=(10, 5)) ax = plt.axes(projection=ccrs.Robinson()) ax.coastlines()x, y = np.meshgrid(np.arange(-179, 181), np.arange(-90, 91)) data = np.sqrt(x**2 + y**2) ax.hexbin(x.flatten(), y.flatten(), C=data.flatten(),gridsize=20, transform=ccrs.PlateCarree()) plt.show()2.引入了古德分瓣投影
fig = plt.figure(figsize=(10, 5)) proj = ccrs.InterruptedGoodeHomolosine(central_longitude=-160,emphasis='ocean') ax = plt.axes(projection=proj) ax.stock_img() plt.show()3.解決了不同投影下的經緯度標注問題
rotated_crs = ccrs.RotatedPole(pole_longitude=120.0, pole_latitude=70.0) ax0 = plt.axes(projection=rotated_crs) ax0.set_extent([-6, 1, 47.5, 51.5], crs=ccrs.PlateCarree()) ax0.add_feature(cfeature.LAND.with_scale('110m')) ax0.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False)plt.figure(figsize=(6.9228, 3)) ax1 = plt.axes(projection=ccrs.InterruptedGoodeHomolosine()) ax1.coastlines(resolution='110m') ax1.gridlines(draw_labels=True)plt.figure(figsize=(7, 3)) ax2 = plt.axes(projection=ccrs.PlateCarree()) ax2.coastlines(resolution='110m') gl = ax2.gridlines(draw_labels=True) gl.top_labels = False gl.right_labels = False plt.show()
4.對圖像進行投影
fig = plt.figure(figsize=(8, 12)) # !wget https://lance-modis.eosdis.nasa.gov/imagery/gallery/2012270-0926/Miriam.A2012270.2050.2km.jpg fname = '/home/mw/project/Miriam.A2012270.2050.2km.jpg' img_extent = (-120.67660000000001, -106.32104523100001, 13.2301484511245, 30.766899999999502) img = plt.imread(fname) ax = plt.axes(projection=ccrs.PlateCarree()) ax.set_xmargin(0.05) ax.set_ymargin(0.10) ax.imshow(img, origin='upper', extent=img_extent, transform=ccrs.PlateCarree()) ax.coastlines(resolution='50m', color='black', linewidth=1) ax.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False) ax.plot(-117.1625, 32.715, 'bo', markersize=7, transform=ccrs.Geodetic()) ax.text(-117, 33, 'San Diego', transform=ccrs.Geodetic()) plt.show()5.與xarray完美兼容
ds = xr.open_dataset('/home/mw/input/OISSTV27010/anom/sst.day.anom.2015.nc') ds ssta = ds.anom.sel(time='2015-07-01', method='nearest') fig = plt.figure(figsize=(9,6)) ax = plt.axes(projection=ccrs.Robinson()) ax.coastlines() gl = ax.gridlines(draw_labels=True, dms=True, x_inline=False, y_inline=False) gl.top_labels = False gl.right_labels = False ssta.plot(ax=ax, transform=ccrs.PlateCarree(),vmin=-5, vmax=5, cmap=cmaps.cmp_b2r,cbar_kwargs={'shrink': 0.4}) plt.show()6.繪制蘭伯特投影的中國版圖
標準地圖服務:http://211.159.153.75/
標準地圖依據中國和世界各國國界線畫法標準編制而成,可用于新聞宣傳用圖、書刊報紙插圖、廣告展示背景圖、工藝品設計底圖等,也可作為編制公開版地圖的參考底圖。社會公眾可以免費瀏覽、下載標準地圖,直接使用標準地圖時需要標注審圖號。
總結
以上是生活随笔為你收集整理的Cartopy 0.20 最新功能 —— Cartopy 装不上别慌,内附解决方案的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: D3DTOP_DOTPRODUCT3的计
- 下一篇: 人生感悟2