如何利用GeoPandas绘制专题图
发表于:2025-02-09 作者:千家信息网编辑
千家信息网最后更新 2025年02月09日,小编给大家分享一下如何利用GeoPandas绘制专题图,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!练习使用geopand
千家信息网最后更新 2025年02月09日如何利用GeoPandas绘制专题图
小编给大家分享一下如何利用GeoPandas绘制专题图,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
练习使用geopandas绘制专题图,仅供参考。
import pandas as pdimport geopandas as gpimport contextily as ctximport matplotlib.pyplot as pltfrom shapely.geometry import Pointimport matplotlib.patches as mpatchesfrom matplotlib_scalebar.scalebar import ScaleBarchi=gp.read_file("population_data/chi_shp/省.shp").to_crs(epsg=3415)nine_lines = gp.read_file('population_data/chi_shp/chi_nine_dotted_line.shp',encoding='utf-8')tai=gp.read_file("population_data/chi_shp/省.shp")tai=tai[tai['省'].isin(['台**'])].to_crs(epsg=3415)fig=plt.figure(figsize=(8,8)) #设置画布大小ax = plt.gca()ax.set_title(chi.columns.values[1],fontsize=14,loc="left")# 主图绘制chi.plot(ax=ax,color='#E24A33',column="需要绘制的数据列名称",edgecolor='grey',linewidth=0.5,legend=True,legend_kwds={ 'labels':['a','v'], 'loc': 'lower left', 'title': 'Title', 'shadow': False, 'fontsize':8, 'frameon':False, 'prop':{'family': 'Times New Roman', 'weight': 'normal', 'size': 12}})# 添加九**nine_lines.geometry.to_crs(epsg=3415).plot(ax=ax, edgecolor='black', linewidth=2, alpha=0.5)# 添加台**tai.to_crs(epsg=3415).plot(ax=ax,hatch= "////",label= "缺失值",facecolor='lightgrey')# 设置绘图显示范围ax.set(ylim=(-0.3*10**6,4.5*10**6))# 自定义图例文字# get all the legend labels# legend_labels = ax.get_legend().get_texts()# bounds=['q','a']# # replace the legend labels# for bound, legend_label in zip(bounds, legend_labels):# legend_label.set_text(bound)# leg = ax.get_legend()# leg.set_title('Percentage Error (%)',prop={'family': 'Times New Roman', 'weight': 'normal', #'size': 12})# 副图框绘制ax_child = fig.add_axes([0.75, 0.20, 0.15, 0.15]) # left, bottom, width, heightchi.plot(ax=ax_child,color='#E24A33',edgecolor='grey',linewidth=0.5)chi.plot(ax=ax_child,color='#348ABD',edgecolor='grey',linewidth=0.5)ax_child = nine_lines.geometry.to_crs(epsg=3415).plot(ax=ax_child, edgecolor='black', linewidth=2, alpha=0.5)tai.to_crs(epsg=3415).plot(ax=ax_child,hatch= "////",label= "缺失值",facecolor='lightgrey')ax_child.set(xlim=(-0.5*10**6,1.5*10**6),ylim=(-1.5*10**6,0.8*10**6))ax_child.set_xticks([])ax_child.set_yticks([])# 添加省市名称注记# texts=chi.apply(lambda x: ax.annotate(s=x['省'], xy=x.geometry.centroid.coords[0], va='center'# ,fontsize=10,arrowprops=dict(arrow, color='k', lw=0.5)), axis=1)# adjust_text(texts)# 额外图例绘制p1=gp.GeoDataFrame({'geometry':[Point(-1.60*10**6,-0.1*10**6)]})p1.plot(ax=ax,markersize=100,facecolor='lightgrey',hatch= "////")ax.text(-1.54*10**6,-0.15*10**6, "NoData",{'family': 'Times New Roman', 'weight': 'normal', 'size': 12})# 图例操作LegendElement = [ mpatches.Patch(facecolor='#E24A33', linestyle='--', linewidth=1.2, label='1'), mpatches.Patch(facecolor='#348ABD', linestyle='--', linewidth=1.2, label='2') ]ax.legend(handles = LegendElement, loc='lower left',prop={'family': 'Times New Roman', 'weight': 'normal', 'size': 12},frameon=False,shadow=False)# 添加比例尺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)# 添加指北针x, y, arrow_length = 0.42, 0.09, 0.07ax.annotate('N', 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)# 添加底图# ctx.add_basemap(ax,crs="epsg:3415",source=ctx.providers.OpenStreetMap.Mapnik(apiKey="*"))# ctx.add_basemap(ax_child,crs="epsg:3415",source=ctx.providers.OpenStreetMap.CH(apiKey="*"))# 设置刻度# ax.set_axis_off() # ax_child.set_axis_off()ax.set_xticks([])ax.set_yticks([])# 保存地图# plt.savefig("filename",dpi=600,bbox_inches='tight')
输出图大致如下所示:
以上是"如何利用GeoPandas绘制专题图"这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注行业资讯频道!
专题
图例
篇文章
内容
名称
缺失
仅供参考
不怎么
刻度
地图
大小
大部分
指北针
数据
文字
更多
比例
比例尺
画布
省市
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
戴尔核心服务器
搭建app后台服务器
数据库 查询分类
盛开小说软件开发
网络安全防护有哪些公司
互联网推广营销聚顶科技
工控系统网络安全和等级保护
服务器的安全运行和数据备份
停吧互联网科技有限公司
Web服务器怎么设置安全
电脑软件开发自学
文科生适合做软件开发吗
关系数据库最小的数据单位
晨晖网络技术有限公司
新辉软件开发
数据库无法连接jdbc
网络安全问题解决措施和思路
文明重启如何蹲新服务器
深圳市维力思互联网科技有限公司
网络安全演习视频
房山二手服务器回收门店
广州云讯互联网科技
我国网络安全加强的原因
Ns暗黑2连不上服务器怎么加速
黄山专业汽配软件开发价格
互联网科技发展大会哈尔滨
蚌埠信息中心网络安全工作
杭州立码网络技术有限公司
828D没有服务器证书详情
虚拟机服务器管理器在哪里