Cartopyを使用して表示したい衛星画像データがあります。私は正常に画像例hereの詳細を辿った。このコードが得られる:Cartopyでマップ上に画像を表示するときの投影の問題
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
方法でターゲット投影画像の範囲を指定しなかったことです。私はまた、Philが示唆するように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, code not shown
ax.imshow(img, origin='upper', 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, 32.715, 'bo', markersize=7, transform=ccrs.Geodetic())
ax.text(-117, 33, 'San Diego', transform=ccrs.Geodetic())
ax.coastlines()
ax.gridlines()
plt.show()
:
私Cartopy 0.7は1.3をMPLへのアップグレード後に壊れたので、私はカントあなたのためにそれをテストしてください。しかし、あなたのプロットのデータの座標を指定してはいけませんか?もしあなたがいないなら、私は座標が軸投影と等しいと仮定していると思います。ですから、プロットコマンドに 'transform = ccrs.PlateCarree()'を追加してみてください。 –