python绘图设置正交坐标等距_python – 使用cartopy在其他项目中绘制投影数据
這個問題涉及繪制一些使用Lambert Conformal(LCC)CRS的數據.雖然這些問題特別適用于在多個投影中繪制LCC數據,但它也適用于一般的折紙使用,因為我希望更好地理解使用折疊繪圖的邏輯/過程.
下面是我正在嘗試做的一些代碼示例.第一個例子是簡單地繪制一些LCC數據.我使用的數據可在鏈接here中找到.
import cartopy.crs as ccrs
import cartopy.feature as cf
import matplotlib.pyplot as plt
import numpy as np
proj = ccrs.LambertConformal(central_latitude = 25,
central_longitude = 265,
standard_parallels = (25, 25))
# Data and coordinates (from download link above)
with np.load('nam_218_20120414_1200_006.npz') as nam:
dat = nam['dpc']
lat = nam['lat']
lon = nam['lon']
ax = plt.axes(projection = proj)
ax.pcolormesh(lon, lat, dat, transform = ccrs.PlateCarree())
ax.add_feature(cf.NaturalEarthFeature(
category='cultural',
name='admin_1_states_provinces_lines',
scale='50m',
facecolor='none'))
ax.coastlines('50m')
ax.add_feature(cf.BORDERS)
plt.show()
產生的情節可以在這里看到:
LCC地圖上的美國露點
使用cartopy時我的第一個困惑是為什么在繪圖時我總是要轉換為PlateCarree?我最初的想法是pcolormesh調用的transform關鍵字需要LCC投影信息而不是PlateCarree.
接下來,如果我想在另一個投影中繪制我的LCC數據,例如正交,我會像下面這樣做嗎?
# First, transform from LCC to Orthographic
transform = proj.transform_points(ccrs.Orthographic(265,25), lon, lat)
x = transform[..., 0]
y = transform[..., 1]
ax = plt.axes(projection = ccrs.Orthographic(265,25))
ax.pcolormesh(x, y, dat, transform = ccrs.PlateCarree())
ax.add_feature(cf.NaturalEarthFeature(
category='cultural',
name='admin_1_states_provinces_lines',
scale='50m',
facecolor='none'))
ax.coastlines('50m')
ax.add_feature(cf.BORDERS)
ax.set_global()
產生的情節可以在這里看到:
美國露點地圖上的露點
我認為正交圖看起來是正確的,但我想確定我理解正確重新投影的過程.
總之,我想知道以下事項:
>繪圖時你總是要轉變為PlateCarree嗎?為什么或者為什么不?
>重新投影是否只需要調用transform_points方法或是否涉及其他步驟?
更新1
根據@swatchai的答案,似乎我的問題2的答案是不需要transform_points.可以在許多matplotlib繪圖方法中使用transform關鍵字參數.這就是我原來的想法.但是,跳過transform_points并不適用于我.見下面的例子:
ax = plt.axes(projection = ccrs.Orthographic(265,25))
ax.pcolormesh(lon, lat, dat, transform = proj)
ax.add_feature(cf.NaturalEarthFeature(
category='cultural',
name='admin_1_states_provinces_lines',
scale='50m',
facecolor='none'))
ax.coastlines('50m')
ax.add_feature(cf.BORDERS)
ax.set_global()
這產生了這個情節:
正交圖沒有transform_points步驟
問題似乎是lat和lon輸入沒有轉換成網格坐標,所以它們只能繪制在圖的極小區域內.那么,要擴展問題2,如果您應該跳過transform_points,那么基于我上面的例子,是否存在cartopy繪圖方法中的錯誤?或者我還缺少一步?
總結
以上是生活随笔為你收集整理的python绘图设置正交坐标等距_python – 使用cartopy在其他项目中绘制投影数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 换了头像后
- 下一篇: websocket python爬虫_p