大尺度地学研究需要绘制世界地图范围内的地理对象变化。网上很多python matplotlib资料,但很多函数用法都没解释清楚,例如颜色栏使用方法及位置管理等方法。当然一开始就使用GMT(Generic mapping tool)工具绘制地图的想法,证明就是一个彻底的弯路。本文介绍的方法对于绘制小区域变化信息也是适用的,与此同时它也是数据科学专业研究必备。会话多说,直接上代码和图片结果:
import geopandas as gpd
import pandas as pd
import shapely.geometry
import matplotlib
matplotlib.use('Agg')
from shapely.geometry import Polygon
import json
from mpl_toolkits.basemap import Basemap
import plotly.graph_objects as go
from mpl_toolkits.axes_grid1 import make_axes_locatable
import matplotlib.pyplot as plt
import shapefile as shp
import seaborn as sns
import numpy as np
import matplotlib as mpl
sns.set(style="whitegrid", palette="pastel", color_codes=True)
sns.mpl.rc("figure", figsize=(10,6))
if __name__ == "__main__":
#serach a different projection of the basemap
m = Basemap(resolution='c',
projection='kav7',
lat_0=0., # Center around
lon_0=0.) # lat 0, lon 0
m.drawcoastlines()
m.fillcontinents(color='coral',lake_color='aqua')
# draw parallels and meridians.
m.drawparallels(np.arange(-90.,91.,30.))
m.drawmeridians(np.arange(-180.,181.,60.))
m.drawmapboundary(fill_color='aqua')
#plt.title("Mercator Projection")
n_graticules = 18.
parallels = np.arange(-80., 90, n_graticules)
meridians = np.arange(0., 360., n_graticules)
lw = 1
dashes = [5,7] # 5 dots, 7 spaces... repeat
graticules_color = 'grey'
fig1 = plt.figure(figsize=(16,20))
fig1.patch.set_facecolor('#e6e8ec')
ax = fig1.add_axes([0