python绘图设置正交坐标等距_python – 使用cartopy在其他项目中绘制投影数据
這個(gè)問題涉及繪制一些使用Lambert Conformal(LCC)CRS的數(shù)據(jù).雖然這些問題特別適用于在多個(gè)投影中繪制LCC數(shù)據(jù),但它也適用于一般的折紙使用,因?yàn)槲蚁M玫乩斫馐褂谜郫B繪圖的邏輯/過程.
下面是我正在嘗試做的一些代碼示例.第一個(gè)例子是簡單地繪制一些LCC數(shù)據(jù).我使用的數(shù)據(jù)可在鏈接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()
產(chǎn)生的情節(jié)可以在這里看到:
LCC地圖上的美國露點(diǎn)
使用cartopy時(shí)我的第一個(gè)困惑是為什么在繪圖時(shí)我總是要轉(zhuǎn)換為PlateCarree?我最初的想法是pcolormesh調(diào)用的transform關(guān)鍵字需要LCC投影信息而不是PlateCarree.
接下來,如果我想在另一個(gè)投影中繪制我的LCC數(shù)據(jù),例如正交,我會(huì)像下面這樣做嗎?
# 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()
產(chǎn)生的情節(jié)可以在這里看到:
美國露點(diǎn)地圖上的露點(diǎn)
我認(rèn)為正交圖看起來是正確的,但我想確定我理解正確重新投影的過程.
總之,我想知道以下事項(xiàng):
>繪圖時(shí)你總是要轉(zhuǎn)變?yōu)镻lateCarree嗎?為什么或者為什么不?
>重新投影是否只需要調(diào)用transform_points方法或是否涉及其他步驟?
更新1
根據(jù)@swatchai的答案,似乎我的問題2的答案是不需要transform_points.可以在許多matplotlib繪圖方法中使用transform關(guān)鍵字參數(shù).這就是我原來的想法.但是,跳過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()
這產(chǎn)生了這個(gè)情節(jié):
正交圖沒有transform_points步驟
問題似乎是lat和lon輸入沒有轉(zhuǎn)換成網(wǎng)格坐標(biāo),所以它們只能繪制在圖的極小區(qū)域內(nèi).那么,要擴(kuò)展問題2,如果您應(yīng)該跳過transform_points,那么基于我上面的例子,是否存在cartopy繪圖方法中的錯(cuò)誤?或者我還缺少一步?
總結(jié)
以上是生活随笔為你收集整理的python绘图设置正交坐标等距_python – 使用cartopy在其他项目中绘制投影数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 换了头像后
- 下一篇: emwin添加图标和图片