Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Python to make GDP Distribution Map in China

2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces "how to use Python to make China's GDP distribution map". In the daily operation, I believe many people have doubts about how to use Python to make China's GDP distribution map. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use Python to make China GDP distribution map". Next, please follow the editor to study!

Data reading # # Import related module import pandas as pdimport geopandas as gpdimport numpy as np import matplotlib.pyplot as pltfrom shapely.geometry import Pointimport matplotlib.patches as mpatchesfrom mpl_toolkits.basemap import Basemapfrom matplotlib_scalebar.scalebar import ScaleBarplt.rcParams ['font.family'] = [' sans-serif'] plt.rcParams ['font.sans-serif'] = [' SimHei'] # replace sans-serif font with boldface plt.rcParams ['axes.unicode_minus'] = False # solution Negative sign display problem regibns = gpd.GeoDataFrame.from_file ("F:\ ArcGIS\ ArcGIS file\ national\ map of China\ provincial administrative region .shp") regibns.plot () # # View coordinate system regibns.crs

# # drawing national boundary nine_lines = gpd.read_file ('F:\ ArcGIS\ ArcGIS file\ country\ map of China\ national boundary .shp') nine_lines.plot ()

# # jingwei = gpd.GeoDataFrame.from_file ('F:\ ArcGIS\ ArcGIS file\ national map\ China\ .shp') fig = plt.figure (figsize= (8)) # set canvas size ax= plt.gca () regibns.plot (ax=ax) jingwei.plot (ax=ax) nine_lines.plot (ax=ax)

Taiwan = gpd.GeoDataFrame.from_file ("F:\ ArcGIS\ ArcGIS file\ national\ map of China\ provincial administrative region .shp") taiwan = taiwan [regibns ['NAME'] .isin ([' Taiwan'])] taiwan.plot ()

Data cleaning regibns = regibns [['GDP_1994 (', 'GDP_1997 (', 'GDP_1998 (', 'GDP_1999 (', 'GDP_2000 (', 'NAME','geometry']] regibns = regibns.rename (columns= {' GDP_1994 (': 'GDP_1994','GDP_1997 (': 'GDP_1997','GDP_1998 (': 'GDP_1999','GDP_2000 (': 'GDP_2000'}) regibns.head ())

Data = pd.read_excel ('provinces of China GDP.xlsx') data.shape

Data.head ()

Data connection GDP = pd.merge (regibns,data,on='NAME') # # Connect GDP.head ()

Drawing # # drawing GDP distribution map of China in 2020 fig = plt.figure (figsize= (12jue 12)) # setting canvas size ax = plt.gca () ax.set_title ("GDP distribution map of provincial administrative units in China in 2020 (unit: 100 million yuan)", fontsize=24,loc='center') regibns ['coords'] = regibns [' geometry'] .apply (lambda x: x.representative_point (). Coords [0]) for n I in enumerate (regibns ['coords']): plt.text (I [0], I [1], regibns [' NAME'] [n], size=12) # main drawing GDP.plot (ax=ax,column='GDP_2020',scheme='quantiles',legend=True,linewidth=0.5,cmap='Reds',edgecolor='k',legend_kwds= {'loc':' lower left', 'title':' legend', 'shadow': True,' fontsize':12, 'frameon':True 'prop': {' family': 'Times New Roman',' weight': 'normal',' size': 12}) jingwei.plot (ax=ax,linewidth=2,alpha=0.5,edgecolor='black') nine_lines.plot (ax=ax,edgecolor='black',linewidth=2,alpha=0.5) taiwan.plot (ax=ax,hatch= "/", label= "missing value", facecolor='lightgrey') # draw ax_child = fig.add_axes ([0.72,0.20,0.15) ) # left, bottom, width, heightGDP.plot (ax=ax_child,color='#E24A33',edgecolor='grey',linewidth=0.5) GDP.plot (ax=ax_child,color='#348ABD',edgecolor='grey',linewidth=0.5) ax_child = nine_lines.geometry.plot (ax=ax_child,edgecolor='black',linewidth=2,alpha=0.5) taiwan.plot (ax=ax_child,hatch= "/", label= "missing value" Facecolor='lightgrey') ax_child.set (xlim=), ylim= (0,10) 6) ax_child.set_xticks ([]) ax_child.set_yticks ([]) # extra legend drawing p1=gpd.GeoDataFrame ({'geometry': [Point (- 1.60) 10)]}) p1.plot (ax=ax,markersize=100,facecolor='lightgrey' Hatch= "/") ax.text (- 1.54 million 10 weight': 6, NoData, {'family':' Times New Roman', 'weight':' normal', 'size': 12}) # add scale scalebar = ScaleBar (dx=1*10**-3,units='km',length_fraction=0.1, font_properties= {' family': 'Times New Roman',' weight': 'normal') 'size': 12}, location=8,sep=1,frameon=False) ax.add_artist (scalebar) # add north compass x, y, arrow_length = 0.42,0.09, 0.07ax.annotate (' nasty, xy= (x, y), xytext= (x, y-arrow_length), arrowprops=dict (facecolor='black', width=4, headwidth=7), ha='center', va='center', fontsize=10 Xycoords=ax.transAxes) # plt.savefig ('map of GDP distribution of provincial administrative units in China in 2020. PNG', dpi=300)

Batch drawing

In order to make the picture convenient, controllable and beautiful, so it is brief.

Reg = GDP.copy () # # good habit The data do not interfere with the table expression data_plot = [('GDP_1994',' China 1994 GDP distribution map (unit: 100 million yuan)'), ('GDP_1997',' China 1997 GDP distribution map (unit: 100 million yuan)'), ('GDP_1998',' China 1998 GDP distribution map (unit: 100 million yuan)'), ('GDP_1999',' China 1999 GDP distribution map (unit: 100 million yuan)'), ('GDP_2000' 'China 2000 GDP distribution map (unit: 100 million yuan), (' GDP_2010',' China 2010 GDP distribution map (unit: 100 million yuan)'), ('GDP_2019',' China 2019 GDP distribution map (unit: 100 million yuan)'), ('GDP_2020',' China 2020 GDP distribution map (unit: 100 million yuan)'),] # batch production map Don't forget Taiwan for m, cal in enumerate (data_plot): reg ['coords'] = reg [' geometry'] .apply (lambda x: x.representative_point (). Coords [0]) ax= reg.plot (figsize= (10,10), column=cal [0], scheme='quantiles', legend=True, cmap='Reds', edgecolor='k') taiwan.plot (ax=ax,hatch= "/", label= "missing value", facecolor='lightgrey') for n I in enumerate (regibns ['coords']): plt.text (I [0], I [1], regibns [' NAME'] [n], size=12) plt.title (cal [1], size=20) plt.grid (True, alpha=0.3) # plt.savefig (str (m) + '.png', dpi=300)

# # drawing a subgraph fig=plt.figure (figsize= (15Power30)) for m, cal in enumerate (data_plot): reg ['coords'] = reg [' geometry'] .apply (lambda x: x.representative_point (). Coords [0]) ax= reg.plot (ax=plt.subplot (4Power2), column=cal [0], figsize= (10), scheme='quantiles', legend=True, cmap='Reds', edgecolor='k') taiwan.plot (ax=ax,hatch= "/", label= "missing value" Facecolor='lightgrey') for n, i in enumerate (regibns ['coords']): plt.text (I [0], I [1], regibns [' NAME'] [n], size=12) # plt.subplots_adjust (bottom=0.1, right=0.6, top=0.5) plt.title (cal [1], size=20) plt.grid (True, alpha=0.3) plt.savefig

Animation # # create folder def mkdir (path): folder = os.path.exists (path) if not folder: # determine whether there is a folder if it does not exist, create a file for the folder os.makedirs (path) # makedirs will create the path print ("- new folder..." if the path does not exist -") print ("-OK-") else: print ("-There is this folder!-- ") file = ritual F:\ ArcGIS\ ArcGIS file\ National\ China Map ArcGIS exercise data\ Code\ photo'mkdir (file) # call function # # copy file import shutilarray = np.arange (9) ls=list (array) rs=map (str Ls) path=r'F:\ ArcGIS\ ArcGIS file\ national\ Chinese map ArcGIS exercise data\ code'# folder to be read root ='F:\ ArcGIS\ ArcGIS file\ national\ Chinese map ArcGIS exercise data\ code\ photo'num=0for num in range (8): name = str (num) + '.png' # select 0-8 if name in os.listdir (path): # take out the file name number is 18x file sourcefile = os.path.join (path Name) # spelling path print (sourcefile) shutil.copy (sourcefile, root) # copy the specified files to the folder in root else: print ("no")

# # drawing # _ * _ coding:utf-8 _ * _ import matplotlib.pyplot as pltimport imageiofrom PIL import Image, ImageSequence__author__ = 'admin'GIF= [] filepath = ritual F:\ ArcGIS\ ArcGIS file\ National\ China Map ArcGIS exercise data\ code\ photo'# file path filenames=os.listdir (filepath) for filename in os.listdir (filepath): GIF.append (imageio.imread (filepath+ "\\" + filename) imageio.mimsave (filepath+ "\" +' result.gif') GIF,duration=1) # this duration is the playback speed The smaller the number, the faster the speed.

At this point, the study on "how to use Python to make the GDP distribution map of China" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report