怎么用Python实现中国地图
发表于:2025-02-19 作者:千家信息网编辑
千家信息网最后更新 2025年02月19日,这篇文章主要讲解了"怎么用Python实现中国地图",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"怎么用Python实现中国地图"吧!代码如下:impo
千家信息网最后更新 2025年02月19日怎么用Python实现中国地图
这篇文章主要讲解了"怎么用Python实现中国地图",文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习"怎么用Python实现中国地图"吧!
代码如下:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import Basemap
import cmaps
import shapefile
from matplotlib.path import Path
from matplotlib.patches import PathPatch
ny = grid_z.shape[0]
nx = grid_z.shape[1]
fig=plt.figure(figsize=(16,9))
plt.rc('font',size=15,weight='bold')
ax=fig.add_subplot(111)
plt.title(u'd_rmse_tmax_012_24h',size=25,weight='bold')
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[i+1]):
vertices.append((pts[j][0], pts[j][1]))
codes += [Path.MOVETO]
codes += [Path.LINETO] * (prt[i+1] - prt[i] -2)
codes += [Path.CLOSEPOLY]
clip = Path(vertices, codes)
clip = PathPatch(clip, transform=ax.transData)
levels=np.linspace(-0.2,0.2,21)
lons, lats = mp.makegrid(nx, ny) # get lat/lons of ny by nx evenly space grid.
x, y = mp(lons, lats)
cf=mp.contourf(x,y,grid_z,levels=levels,extend='both',cmap=cmaps.MPL_bwr)
for contour in cf.collections:
contour.set_clip_path(clip)
cbar=mp.colorbar(cf,location='right',format='%8.2f',size=0.3,ticks=np.linspace(-0.2,0.2,11))
left, bottom, width, height = 0.15, 0.63, 0.25, 0.25
plt.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()
出图效果如下:
感谢各位的阅读,以上就是"怎么用Python实现中国地图"的内容了,经过本文的学习后,相信大家对怎么用Python实现中国地图这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是,小编将为大家推送更多相关知识点的文章,欢迎关注!
中国地图
地图
中国
学习
内容
代码
出图
就是
思路
情况
效果
文章
更多
知识
知识点
篇文章
跟着
问题
实践
推送
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
语言类及数据库科目
地区网络安全工作报告
网络安全学校国家队
为知笔记自建服务器新版本
巨杉数据库查看同步状态
软件开发质保期如何描述
网络安全知识作用
软件开发必须与方案一致吗
宁夏软件开发定制价格
软件开发试用
饿了么的数据库
校时服务器地址
起重设备管理软件开发
全社会网络安全培训
软件开发流程图用符号
上海公司软件开发
互联网科技公司绘图用什么软件
济南erp软件开发怎么收费
境外网络安全检查
沧州华胜网络技术有限公司
宝山区网络技术转让要多少钱
网络安全教育新模式
app软件开发解决方案怎么样
软件开发有必要i7吗
广州软件开发石家庄
软件开发工资的几个坎
阿里云数据库备份机制
松江区营销软件开发五星服务
网络技术应用实践指导江苏
银率网 数据库