散点图不会在底图上绘制任何点 [英] Scatter does not plot any points on Basemap

查看:127
本文介绍了散点图不会在底图上绘制任何点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个以这种方式创建的数组anomalies_ind:

I have an array anomalies_ind that was created in this way:

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

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

The first element represents the day in the month of January, while the 2nd and 3rd elements represent longitude and latitude respectively. I am trying to plot points at the longitudes and latitudes given on map like so:

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()

但是,地图上没有点.有人知道怎么了吗?

However, no points are on the map. Does anyone know what is wrong?

这是真实的foo数组的一些值"

Here are some values of the real foo array"

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

推荐答案

我自己遇到了这个问题.

I've run into this problem, myself.

底图绘图功能有一个latlon关键字,对此进行了更改.默认值为latlon=False,因此x和y值将解释为投影坐标.添加latlon=True告诉底图将x和y值解释为地图坐标.

Basemap plotting functions have a latlon keyword, and changing this worked for me. The default is latlon=False, so that x and y values are interpreted as projection coordinates. Adding latlon=True tells Basemap to interpret x and y values as map coordinates.

在此处分散查看底图文档: http://matplotlib.org/basemap/api/basemap_api. html#mpl_toolkits.basemap.Basemap.scatter

See the Basemap documentation on scatter here: http://matplotlib.org/basemap/api/basemap_api.html#mpl_toolkits.basemap.Basemap.scatter

在您的原始绘图语法中,您需要更改行:

In your original plotting syntax, you'll want to change the line:

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

收件人:

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

这篇关于散点图不会在底图上绘制任何点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆