介绍
最近需要绘制中国地图,由于之前都是非常简单地直接绘制地图已不可取!因此严格按照规定来直接一张中国地图。
所需材料
下载中国地图shape
中国气象站点数据
代码
下面直接贴代码和最终结果图形。
import os
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
from mpl_toolkits.axes_grid1.inset_locator import inset_axes, zoomed_inset_axes
homedir = os.path.dirname(os.path.realpath(__file__))
output_type = 'png'
fig = plt.figure(figsize=(5,3))
ax = fig.add_subplot(111, position=[0.08,0.08,0.84,0.82])
axins = zoomed_inset_axes(ax, zoom=0.8, loc='lower right')
m = Basemap(projection='cyl', llcrnrlat=15, llcrnrlon=73, urcrnrlat=56, urcrnrlon=137, ax=ax)
m.readshapefile(os.path.join(homedir, 'shp', 'china_country'), 'china_country')
m.readshapefile(os.path.join(homedir, 'shp',"china_nine_dotted_line"), 'nine_dotted', drawbounds=True)
# 绘制站点
m_lon, m_lat = m(stainfos.lon.values, stainfos.lat.values)
m.scatter(m_lon, m_lat, s=1, color='r', zorder=10)
# 绘制地形?
m2 = Basemap(projection='cyl', llcrnrlat=0, llcrnrlon=107, urcrnrlat=20, urcrnrlon=121)
m2.readshapefile(os.path.join(datadir, 'shp', 'china_country'), 'china_country')
m2.readshapefile(os.path.join(datadir, 'shp',"china_nine_dotted_line"), 'nine_dotted', drawbounds=True)
m2_logical = stainfos.lat <= 25
m_lon, m_lat = m2(stainfos[m2_logical].lon.values, stainfos[m2_logical].lat.values)
m2.scatter(m_lon, m_lat, s=1, c='r', zorder=10)
m.drawparallels(np.arange(10, 60 + 1, 5), labels = [1, 1, 0, 0])
m.drawmeridians(np.arange(70, 150 + 1, 10), labels = [0, 0, 1, 1])
fileout = os.path.join(homedir, f'000-research_area.{output_type}')
plt.savefig(fileout, dpi=300)