中国地图

基本地图

import pandas as pd
from matplotlib.colors import rgb2hex
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

### 1. 中国基本地图
map = Basemap(
	llcrnrlon=77,
	llcrnrlat=14,
	urcrnrlon=140,
	urcrnrlat=51,
	projection=\'lcc\',
	lat_1=33,
	lat_2=45,
	lon_0=100
)

map.drawcountries(linewidth=1.5)
map.drawcoastlines()
plt.show()

城市地图

import pandas as pd
from matplotlib.colors import rgb2hex
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from matplotlib.patches import Polygon
import pandas as pd
cmap = plt.cm.YlOrRd

map = Basemap(
   llcrnrlon=77,
   llcrnrlat=14,
   urcrnrlon=140,
   urcrnrlat=51,
   projection=\'lcc\',
   lat_1=33,
   lat_2=45,
   lon_0=100
)
map.readshapefile("./gadm36_CHN_shp/gadm36_CHN_2", \'states\', drawbounds=True)
map.readshapefile("./gadm36_TWN_shp/gadm36_TWN_2", \'taiwan\', drawbounds=True)

map.drawcoastlines()
map.drawcountries(linewidth=1.5)

plt.show()

pd.read_excel(\'./gadm36_TWN_shp/A0101a.xls\') 

statenames = []
colors = {}


vmax = 100000000
vmin = 2000000

for shapedict in map.states_info:
	statenme = shapedict[\'NL_NAME1\']
	p = statenme.split("|")
	print p

地图上色

from matplotlib.patches import Polygon
from matplotlib.colors import rgb2hex
import pandas as pd
from matplotlib.colors import rgb2hex
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt

map = Basemap(
	llcrnrlon=77,
	llcrnrlat=14,
	urcrnrlon=140,
	urcrnrlat=51,
	projection=\'lcc\',
	lat_1=33,
	lat_2=45,
	lon_0=100
)
map.readshapefile("./gadm36_CHN_shp/china",\'china\',drawbounds=True)
map.readshapefile("./gadm36_CHN_shp/china_nine_dotted_line",\'nine_dotted\',drawbounds=True)
cmap = plt.cm.YlOrRd
ax = plt.gca()
for nshape,seg in enumerate(map.china):
	color = rgb2hex(cmap(nshape)[:3])
	poly = Polygon(seg,facecolor=color,edgecolor=color)
	ax.add_patch(poly)
plt.show()

provinces = set()

#  china_info 是 地图中的省份信息
for shapdict in map.china_info:
	statename = shapdict[\'OWNER\']
	provinces.add(statename.replace(\'\x00\',\'\'))
print provinces
stations_lon_lat  = pd.read_csv()

版权声明:本文为dengz原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/dengz/p/14835578.html