2017-08-04 135 views
1

任何點我有一個數組anomalies_ind這是以這種方式創建:散點圖不上繪製底圖

data_path = r"C:\Users\matth\Downloads\TRMM_3B42RT\3B42RT_Daily.201001.7.nc4" 
f = Dataset(data_path) 

latbounds = [ -45 , -10 ] 
lonbounds = [ 105, 160 ] 
lats = f.variables['lat'][:] 
lons = f.variables['lon'][:] 

# latitude lower and upper index 
latli = np.argmin(np.abs(lats - latbounds[0])) 
latui = np.argmin(np.abs(lats - latbounds[1])) 

# longitude lower and upper index 
lonli = np.argmin(np.abs(lons - lonbounds[0])) 
lonui = np.argmin(np.abs(lons - lonbounds[1])) 

precip_subset = f.variables['precipitation'][ : , lonli:lonui , latli:latui ] 

data_low_indices1 = np.where((precip_subset > 0) & (precip_subset < 1)) 
data_low_indices2 = np.array(np.where((precip_subset > 0) & (precip_subset < 1))).T 
anomalies_ind = [] 
for ind in data_low_indices2: 
    anomalies_ind.append(ind) 
    print(np.asarray(anomalies_ind)) 

這樣做的輸出是這樣的:

[[1, 23, 45] 
[3, 45, 56] 
... 
[31, 45, 89]] 

第一元素表示天在1月份,第二和第三元素分別代表經度和緯度。我想在地圖上給出像這樣的經度和緯度積點:

foo = np.asarray(anomalies_ind) 
longs = foo[:,1] 
lat = foo[:,2] 
m = Basemap(llcrnrlon=105.,llcrnrlat=-45,urcrnrlon=160,urcrnrlat=-10) 
m.drawcoastlines() 
m.fillcontinents(color = 'lightgray', zorder = 0) 
m.scatter(longs, lat, marker = 'o', color = 'k', zorder=10) 
plt.show() 

然而,沒有點在地圖上。有誰知道什麼是錯的?

編輯:這裏是真正的foo陣列」

[[ 0 0 0] 
[ 0 0 16] 
[ 0 0 17] 
..., 
[ 30 219 113] 
[ 30 219 114] 
[ 30 219 116]] 
+0

如果您不要填滿大陸,你能看到分散?如果你甚至不畫海岸線呢? – cphlewis

+0

@cphlewis:我已經試過了。我認爲這個問題可能是'longs = foo [:,1]'和'lat = foo [:,2]' –

回答

2

我碰到這個問題,我自己

底圖繪圖功能有一個latlon關鍵字,並改變這對我有用。默認值是latlon=False,以便將x和y值解釋爲投影座標。添加latlon=True告訴底圖將x和y值解釋爲地圖座標。

看到這裏上分散的底圖文檔: http://matplotlib.org/basemap/api/basemap_api.html#mpl_toolkits.basemap.Basemap.scatter

在原始的繪圖語法,你要改線:

m.scatter(longs, lat, marker = 'o', color = 'k', zorder=10) 

到:

m.scatter(longs, lat, marker = 'o', color = 'k', zorder=10, latlon=True) 
1

你有你的緯度轉換ANS經度調用散射之前地圖投影的一些值:

x,y=m(longs,lat) 
m.scatter(x, y, marker = 'o', color = 'k', zorder=10) 
+0

感謝您的迴應。但是,地圖上仍然沒有顯示任何點數。 –

+0

你的多頭,拉特不對應於澳大利亞 – Serenity

+0

我在我的問題中給出的指標只是例子。真實指數確實與澳大利亞相符。 –