Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to realize the Map of China with Python

Shulou Source: shulou.com Published: 2022-06-02 05:21:46 10月01日 Update

This article mainly explains "how to use Python to realize the map of China". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use Python to realize the map of China".

The code is as follows:

Import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.basemap import Basemapimport cmapsimport shapefilefrom matplotlib.path import Pathfrom matplotlib.patches import PathPatch

Ny = grid_z.shape [0] nx = grid_z.shape [1] fig=plt.figure (figsize= (16par 9)) plt.rc ('font',size=15,weight='bold') ax=fig.add_subplot (111) plt.title (upright rmseqtmax012) 24hr weightweights mp=Basemap (llcrnrlon=73.,llcrnrlat=15.,urcrnrlon=136.,urcrnrlat=55,projection='cyl') CHN='G:\\ DATA\\ MAP\\ china-shapefiles-master\\' mp.readshapefile (CHN+'china','china' Drawbounds=True) sf = shapefile.Reader (CHN+'china_country') for shape_rec in sf.shapeRecords (): if shape_rec.record [8] = 'CHN': vertices = [] codes = [] pts = shape_rec.shape.points prt = list (shape_rec.shape.parts) + [len (pts)] for i in range (len (prt)-1): for j in range (PRT [I] Prt [iTun1]): vertices.append ((pts [j] [0], pts [j] [1])) codes + = [Path.MOVETO] codes + = [Path.LINETO] * (prt [iTun1]-prt [I]-2) codes + = [Path.CLOSEPOLY] clip = Path (vertices, codes) clip = PathPatch (clip, transform=ax.transData) levels=np.linspace Lats = mp.makegrid (nx, ny) # get lat/lons of ny by nx evenly space grid.x, y = mp (lons, lats) cf=mp.contourf 0.25plt.axes ([bottom, left, width, height]) mf=Basemap (llcrnrlon=107.,llcrnrlat=2.,urcrnrlon=122.,urcrnrlat=22,projection='cyl') CHN='G:\\ DATA\\ MAP\\ china-shapefiles-master\\ 'mf.readshapefile (CHN+'china','china',drawbounds=True) CHN='G:\\ DATA\\ MAP\\ china-shapefiles-master\' mf.readshapefile (CHN+'china_nine_dotted_line','china_nine_dotted_line',drawbounds=True Linewidth=1.5) mf.drawcoastlines () plt.show ()

The effect of drawing is as follows:

Thank you for your reading, the above is the content of "how to use Python to realize the map of China". After the study of this article, I believe you have a deeper understanding of how to use Python to achieve the map of China, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Chinese map map China learning content code drawing that is ideas situations effects articles more knowledge knowledge points articles follow questions practice push Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno Redmi vpn Shulou Information Xiaomi