([[[21.897421.8974003,83 83.393939393939742003,83.3939394949494949494949494949494949494949494949494949494949499999999999,,[,[[21 21 21 79.9492978],[39.1767262,-94.4867155],[33.7489954,-84.3879824],[39.7392358,-39.7392358,-104.990251],[38.8761634,-77.0337777],[41.0082376,28.9783589],[36.0753128,-95.956462699999],[36.0595387,-95.9058242499999],[29.7604267,-95.3698028],[21.3014947,106.6291304],[21.3014947,106.6291304],[21.3014947,106.624947,106.6291304],[38.87616338.8761634,-38.8761634,-77.033777.033737.03373838383838388738.38.38.38.,[45.037149,-92.825929],[33.760818,-78.967556],[45.4934036999999,-73.82329179999999],[39.750545,37.0150217])
< /代码> <
这是我的代码:
import geocoder
import json
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
def openJSON(file, path):
with open(path + file + '.json', 'r') as fp:
data = json.load(fp)
return data
def App_users(data):
android_users = []
iphone_users = []
other_users = []
#3 types of users: Android, Iphone and others:
for a, b, c, d in data:
if "Twitter for Android" in d:
android_users.append([a, b])
elif "Twitter for iPhone" in d:
iphone_users.append([a, b])
else:
other_users.append([a, b])
data = (android_users, iphone_users, other_users)
return data
if __name__ == '__main__':
posXY_add = []
for d in data[0:50]:
if d["user"]["location"] != None:
g = geocoder.google(d["user"]["location"])
if g.latlng != None:
a = g.latlng + [g.address] + [str(d["source"])]
posXY_add.append(a)
data = App_users(posXY_add)
map = Basemap(llcrnrlat=-70, urcrnrlat=70,
llcrnrlon=-180, urcrnrlon=180, epsg=3395)
map.arcgisimage(service='ESRI_Imagery_World_2D', xpixels = 1500, verbose= True)
colors = ['r', 'g', 'b']
increment = 0
for app in data:
for item in app:
if len(item) == 2:
lat, lon = item[0], item[1]
x, y = map(lon, lat)
map.plot(x, y, colors[increment] + 'o')
increment += 1
plt.title("Geo-position Twitter Devices")
plt.show()
你有什么建议要改进我的地图吗?不同的颜色,不同的地图还是其他?
我使用的是pycharm的python 2.7。我的示例数据是:
([[21.8974003, 83.39496319999999], [40.2671941, -86.1349019], [10.4805937, -66.90360629999999]], [[50.719164, -1.880769], [37.0903748, -94.5134078], [44.9862701, -93.39398279999999], [47.6062095, -122.3320708], [-27.4697707, 153.0251235], [20.593684, 78.96288]], [[43.2648545, -79.9492978], [39.1767262, -94.4867155], [33.7489954, -84.3879824], [39.7392358, -104.990251], [38.8761634, -77.0337777], [41.0082376, 28.9783589], [36.0753128, -95.95646269999999], [36.0595387, -95.90582429999999], [29.7604267, -95.3698028], [21.3014947, 106.6291304], [21.3014947, 106.6291304], [-16.6868982, -49.2648114], [10.4805937, -66.90360629999999], [45.037149, -92.825929], [33.760818, -78.967556], [45.49340369999999, -73.82329179999999], [39.750545, 37.0150217]])