基本上我有一个填充纬度和经度数据的csv,我将其添加到数据框中的两个单独的列中。然后使用它来创建一个包含所有数据的地球仪。除了数据没有正确绘图,我不知道为什么。
读入数据文件并将其添加到csv。
data_col = ['IP', 'Reliability', 'Risk', 'Type', 'Country', 'Locale', 'Co-Ords', '?']
data = pd.read_csv('reputation.data', sep='#', names=data_col)
获取Co-Ords列并将其拆分为两个不同的列
data['Co-Ords'] = data['Co-Ords'].str.replace('ut: ','')
data['lat'] = data['Co-Ords'].apply( lambda x: x.split(',')[0] )
data['lon'] = data['Co-Ords'].apply( lambda x: x.split(',')[1] )
将数据实施到底图;
m1 = Basemap(projection='ortho', lon_0=4,lat_0=46, resolution='l')
fig=plt.figure(figsize=(12, 6))
m1.drawmapboundary(fill_color='black')
m1.fillcontinents(color='white',lake_color='black')
m1.drawcoastlines()
m1.drawcountries()
x=(data['lat']).as_matrix()
y=(data['lon']).as_matrix()
m1.scatter(x,y,cmap=cm.cool,marker="*", color='r', alpha=0.7,
latlon=True, zorder=10)
plt.title("IP Addresses on the Globe")
plt.show()
它看起来如下: Globe
感谢帮助。
编辑:我从
中读取的数据IP Reliability Risk Type Country Locale Co-Ords ? lat lon
46.4.123.15 4 2 Malicious DE NaN 51.0,9.0 3 51 9
116.117.253.243 3 2 Scanning CN Baotou 40.6521987915,109.82219696 11 40.6521987915 109.82219696
123.59.59.89 4 2 Malicious CN Beijing 39.9289016724,116.388298035 3 39.9289016724 116.388298035
123.59.71.2 4 2 Malicious CN Beijing 39.9289016724,116.388298035 3 39.9289016724 116.388298035
123.59.149.74 4 2 Malicious CN Beijing 39.9289016724,116.388298035 3 39.9289016724 116.388298035
答案 0 :(得分:0)
您需要convert your longitude and latitude to map coordinates通过x, y = m1(x, y)
。在下面的代码中,我用这一行替换了那一行和你的矩阵转换,我认为更清楚:y,x = m1(data['lon'].values, data['lat'].values)
此代码对我有用
m1 = Basemap(projection='ortho', lon_0=4,lat_0=46, resolution='l')
fig=plt.figure(figsize=(12, 6))
m1.drawmapboundary(fill_color='black')
m1.fillcontinents(color='white',lake_color='black')
m1.drawcoastlines()
m1.drawcountries()
x,y = m1(data['lon'].values, data['lat'].values)
m1.scatter(x,y, marker="*", color='r', alpha=0.7, zorder=10)
plt.title("IP Addresses on the Globe")
plt.show()