当前位置:网站首页>Map basemap Library

Map basemap Library

2022-04-23 18:00:00 Be happy to study today

Basemap Study

api manual

https://matplotlib.org/basemap/api/basemap_api.html

install basemap library

First installation geos library
pip install geos
Then install basemap library , Install at basemap Of whl file ( Note that version )
https://www.lfd.uci.edu/~gohlke/pythonlibs/#basemap
And then use pip Command after installation , You can use

Make a map

import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import numpy as np

# To create a geographic point list
long=[113.8,114,114.5,113.7,114.8,114]
lat=[30,31.2,30,30.5,31,30.5]
gridid=[1,2,3,4,5,6]
count=[10,5,1,22,4,30]

# Drawing base map 
map = Basemap(llcrnrlon="113.6",llcrnrlat="29.971819",urcrnrlon="115.2",urcrnrlat="31.362913",\
            resolution='h',projection='aea',\
            lat_1=25,lat_2=47,lon_0=105,lat_0=30)
            
# Load vector basemap 
filepath = r"E:\code\test5\wuhan.shp"
file = map.readshapefile(filepath[:-4],"Shp",default_encoding='gbk',color="#3641e5")
# Draw points 
x, y = map(long, lat)
pointsize = (count-np.min(count)/(np.max(count)-np.min(count)))*10 #  Calculate the size of each point 
map.scatter(x, y, marker='o',c=range(len(gridid)),s=pointsize)
for a,b,c in zip(x,y,count):
  plt.text(a,b,c,ha='left', fontsize=10)
plt.xlabel('longitude')
plt.ylabel('latitude')
plt.title('wuhan people')
plt.show()
#plt.savefig('wuhanpeople.jpg', dpi=120)

Result chart

 Insert picture description here

版权声明
本文为[Be happy to study today]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230545528401.html