资源简介

ArcGIS出图有时候不好看,运用Basemap可以将shapefile加入到图片中,出图既美观又方便。

资源截图

代码片段和文件信息

from mpl_toolkits.basemap import basemap
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.patches import Polygon
from matplotlib.collections import PatchCollection
from matplotlib.patches import PathPatch
import pandas as pd
from dbfread import DBF
from mpl_toolkits.axes_grid1.inset_locator import inset_axes zoomed_inset_axes
from mpl_toolkits.axes_grid1.inset_locator import mark_inset
from adjustText import adjust_text
import matplotlib.ticker as ticker

plt.style.use(‘boorn‘)
plt.rcParams[‘mathtext.default‘]=‘regular‘
plt.rc(‘font‘family=‘Arial‘size = 6weight=‘bold‘)
fig = plt.figure(dpi=600)
ax = fig.add_subplot(111)

bmap = basemap(epsg=2380llcrnrlon=79llcrnrlat=16
               urcrnrlon=139urcrnrlat=51lat_0=33.5
               lon_0=109resolution=‘l‘ax=axwidth=5height=7.0*5/8)
#bmap.drawcoastlines(linewidth=0.25color=‘b‘)
bmap.drawcountries(linewidth=0.7color=‘k‘)
bmap.drawstates(linewidth=0.5color=‘r‘)
bmap.drawcounties(linewidth=0.5color=‘k‘)
bmap.drawrivers(linewidth=0.1color=‘#a6c2de‘)
bmap.drawmapboundary(fill_color=‘#a6c2de‘linewidth=0.5)
text={‘rotation‘:‘vertical‘}
bmap.drawmeridians(np.arange(7913910)labels=[0001]linewidth=0.5)
bmap.drawparallels(np.arange(165110)labels=[0100]linewidth=0.5**text)
bmap.fillcontinents(color=‘w‘lake_color=‘#a6c2de‘zorder=1)

bmap.readshapefile(‘e:/data/china_province_boundary/province‘
                   ‘province‘color=‘#999999‘linewidth=0.3)
patches   = []
for info shape in zip(bmap.province_info bmap.province):
    patches.append(Polygon(np.array(shape) True))
ax.add_collection(
    PatchCollection(patches facecolor= ‘#fff8dc‘ edgecolor=‘#4F4F4F‘
                    linewidths=0.5 zorder=2))

city_info = bmap.readshapefile(‘e:/research/NDVI_LST/data/shapefile/city30‘‘city‘)
df = pd.Dataframe(iter(DBF(‘e:/research/NDVI_LST/data/shapefile/city30.dbf‘)))
text={‘ha‘:‘center‘‘va‘:‘top‘}
texts=[]
for city_info city in zip(bmap.city_info bmap.city):
    bmap.plot(city[0] city[1] marker=‘.‘ color=‘r‘ markersize=4 markeredgewidth=1)
    if city_info[‘cityname‘]==‘Wuhn‘:
        texts.append(plt.text(city[0]city[1]‘Wuhan‘

评论

共有 条评论