[英]Using longitude and latitude to plot in xarray
我正在嘗試使用 matplotlib 工具箱中的 function imshow
從我的氣候數據集中制作季節性地圖。 我的問題是我只能得到 imshow 到 plot 的邏輯坐標 x 和 y,這使得我的西班牙 map 顛倒了: 我嘗試了不同的方法,我認為我的問題之一可能是我的經度和緯度坐標是二維數據 arrays 而不僅僅是矢量。
所以我的代碼看起來像這樣:
seasonal = PET.groupby('time.season').mean(dim=['time'])
seasonal.plot.imshow(col= 'season', robust = True)
我的數據如下所示:
<xarray.DataArray 'PET' (year: 1, x: 834, y: 1115)>
array([[[nan, nan, nan, ..., nan, nan, nan],
[nan, nan, nan, ..., nan, nan, nan],
[nan, nan, nan, ..., nan, nan, nan],
...,
[nan, nan, nan, ..., nan, nan, nan],
[nan, nan, nan, ..., nan, nan, nan],
[nan, nan, nan, ..., nan, nan, nan]]], dtype=float32)
Coordinates:
lon (x, y) float64 ...
lat (x, y) float64 43.99 43.99 43.99 43.99 ... 35.75 35.75 35.75 35.75
* year (year) int64 2008
Dimensions without coordinates: x, y
有誰知道如何解決這個問題,所以用經度和緯度而不是 x 和 y 顯示圖?
您從對問題的評論中發現imshow
arg, origin='upper'
將以正確的方向顯示您的圖:
seasonal.plot.imshow(col= 'season', robust = True, origin='upper')
到 plot 您的坐標軸在地理 lon、lat 與邏輯 x、y 之間,嘗試使用imshow
arg, extent=[left, right, bottom, top]
來設置坐標軸和 plot 在這些坐標中的邊界。 像這樣的東西:
seasonal.plot.imshow(col= 'season', robust = True, origin='upper', extent=[min(lon), max(lon), min(lat), max(lat)])
您可以在此處的imshow
中閱讀有關原點和范圍 arg 的更多信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.