基本信息
源码名称:绘制桂林市分级统计图.ipynb
源码大小:0.10M
文件格式:.ipynb
开发语言:Python
更新时间:2022-01-20
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 10 元 
   源码介绍
绘制桂林市分级统计图.ipynb

import json

from geojson import Feature, FeatureCollection, Polygon
import geopandas as gpd
import matplotlib.pyplot as plt

# 读取json或者geojson文件并绘图的方法,下面为读取shp文件并绘图的方法
#with open("folium-master/examples/data/桂林市.json", 'rb') as f:
    #districts = json.load(f) 
#districts = gpd.GeoDataFrame.from_features(districts)
#districts.plot()
#districts      


# 加载数据-矢量数据的位置
districts = gpd.GeoDataFrame.from_file('folium-master/examples/data/桂林市/桂林市.shp', encoding='utf-8')
#districts
#districts.plot()

# 加载已搜集的excel数据
import pandas as pd
data = pd.read_excel('folium-master/examples/data/桂林市人口.xlsx') # encoding='utf-8'
#data

# 连接矢量数据属性表与Excel表格
reg = pd.merge(districts, data, left_on='adcode', right_on='id')
# 复制整张表
reg02 = reg.copy()
reg02['coords'] = reg02['geometry'].apply(lambda x: x.representative_point().coords[0])
#reg02

font = {'family' : 'serif',
        'serif': ['Times','STSong'], #['SimSun','Times New Roman'],
        'weight' : 'normal',
        'size'   : '10'}
plt.rc('font', **font)             
plt.rc('axes', unicode_minus=False)

plot = reg02.plot(figsize=(8, 12),  # 图像大小
           column='population',  # 分级设色字段
           scheme='quantiles',  # MapClassify-分级类型
           legend=True,  # 图例
           legend_kwds={"loc": "lower right", "bbox_to_anchor":(1,0)},
           cmap='Reds',  # 渐变色带名称cmaps['Sequential'] = ['Greys', 'Purples', 'Blues', 'Greens', 'Oranges', 'Reds',  #顺序系列
                                                          #'YlOrBr', 'YlOrRd', 'OrRd', 'PuRd', 'RdPu', 'BuPu',
                                                          #'GnBu', 'PuBu', 'YlGnBu', 'PuBuGn', 'BuGn', 'YlGn']
                                                          #cmaps['Diverging'] = [   #发散系列
                                                          #'PiYG', 'PRGn', 'BrBG', 'PuOr', 'RdGy', 'RdBu',
                                                          #'RdYlBu', 'RdYlGn', 'Spectral']
           edgecolor='k')  # 边框颜色
plot.set_xticks([])
plot.set_yticks([])
#plt.axis('off')  #去掉坐标轴
#plt.grid(True, alpha=0.5)  # 显示网格,透明度为50%

plt.text(reg02['coords'][0][0] 0.02, reg02['coords'][0][1] 0.02, reg02['name'][0], 
         size=10, horizontalalignment="right",verticalalignment="bottom")
for n, i in enumerate(reg02['coords'][1:]):
    plt.text(i[0], i[1], reg02['name'][n 1], size=10, horizontalalignment="left")  # 标注位置X,Y,标注内容

fig = plot.get_figure()
fig.savefig('桂林市行政划分图.png',bbox_inches='tight',dpi=800,pad_inches=0.0)

.
└── 好例子网_geopandas-guilin_choropleth.ipynb

0 directories, 1 file