我有一个以这种方式创建的数组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]]


第一个元素代表一月的一天,而第二个和第三个元素分别代表经度和纬度。我正在尝试在地图上给出的经度和纬度上绘制点,如下所示:

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]]

最佳答案

我自己遇到了这个问题。

底图绘图函数有一个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)

关于python - 散点图不会在 basemap 上绘制任何点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45511792/

10-12 18:54