python中basemap温度添加_如何使用python在basemap中添加图例

该博客介绍了如何在Python的Basemap库中创建地理定位的Twitter设备分布图,并展示了如何添加不同颜色以区分不同类型的设备。通过示例代码,作者展示了一个从JSON数据加载地理位置信息并使用Basemap绘制地图的过程,同时询问了关于改进地图,如颜色方案、地图类型或其他元素的建议。
摘要由CSDN通过智能技术生成

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

< /代码> <

70fe852c17dea38162f5af563462e15d.png

这是我的代码:

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值