python用cartopy包画地图_python – 使用Cartopy在地图上显示图像时的投影问题
我有一些我想用Cartopy顯示的衛星圖像數據.我已成功按照圖像示例詳細介紹了here.導致此代碼:
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
fig = plt.figure(figsize=(12,12))
img_extent = (-77,-59,9,26)
ax = plt.axes(projection=ccrs.PlateCarree())
# image data coming from server,code not shown
ax.imshow(img,origin='upper',extent=img_extent)
ax.set_xmargin(0.05)
ax.set_ymargin(0.10)
# mark a known place to help us geo-locate ourselves
ax.plot(-117.1625,32.715,'bo',markersize=7)
ax.text(-117,33,'San Diego')
ax.coastlines()
ax.gridlines()
plt.show()
此代碼生成以下圖像
我的問題是衛星圖像數據不在PlateCarree投影中,而是墨卡托投影.
但是當我得到軸對象時
ax = plt.axes(projection=ccrs.Mercator())
我失去了海岸線.
我看到了here報告的問題.但是
ax.set_global()
得到這張圖片的結果:
數據不存在,圣地亞哥位置錯誤.緯度/經度范圍也發生了變化.我究竟做錯了什么?
發布討論更新
主要問題是我沒有使用transform_points方法在目標投影中正確指定圖像范圍.我還必須具體說明菲爾建議的imshow方法中的坐標參考系統.這是正確的代碼:
import numpy as np
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
proj = ccrs.Mercator()
fig = plt.figure(figsize=(12,12))
extents = proj.transform_points(ccrs.Geodetic(),np.array([-77,-59]),np.array([9,26]))
img_extents = (extents[0][0],extents[1][0],extents[0][6],extents[1][7] )
ax = plt.axes(projection=proj)
# image data coming from server,extent=img_extents,transform=proj)
ax.set_xmargin(0.05)
ax.set_ymargin(0.10)
# mark a known place to help us geo-locate ourselves
ax.plot(-117.1625,markersize=7,transform=ccrs.Geodetic())
ax.text(-117,'San Diego',transform=ccrs.Geodetic())
ax.coastlines()
ax.gridlines()
plt.show()
導致這個正確地理投影的衛星圖像:
總結
以上是生活随笔為你收集整理的python用cartopy包画地图_python – 使用Cartopy在地图上显示图像时的投影问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: html项目符号正方形,html – 列
- 下一篇: 丛林冒险