python通过批量经纬度生成标记地图生成
python通过批量经纬度生成标记地图生成
通过读取excel文件中经纬度数据生成定位图
-
from pyecharts.charts import Geo
-
from pyecharts import options as opts
-
from pyecharts.globals import GeoType
-
import pandas as pd
-
-
-
def mapa():
-
city = 'xx区县'
-
g = Geo(init_opts=opts.InitOpts(width='1850px', height='850px'))
-
g.add_schema(maptype=city)
-
# 定义坐标对应的名称,添加到坐标库中 add_coordinate(name, lng, lat)
-
# 导入excel表举例
-
df = pd.read_excel("学校机构经纬度表.xlsx")
-
df.head()
-
# 导入自定义的地点经纬度
-
for i in range(len(df)):
-
if isinstance(df.iloc[i]['经度'], float):
-
g.add_coordinate(df.iloc[i]['机构名称'], df.iloc[i]['经度'], df.iloc[i]['纬度'])
-
print(df.iloc[i]['机构名称'], df.iloc[i]['经度'], df.iloc[i]['纬度'])
-
# data_pair= [(df.iloc[i]['机构名称'], int(df.iloc[i]['学校类型编号']))]
-
data_pair = [(df.iloc[i]['机构名称'], int(df.iloc[i]['学校类型编号'])) for i in range(len(df)) if
-
isinstance(df.iloc[i]['经度'], float)]
-
-
# 定义数据对,
-
# 将数据添加到地图上
-
g.add('学校地图', data_pair, type_=GeoType.EFFECT_SCATTER, symbol_size=3)
-
# 设置样式
-
g.set_series_opts(label_opts=opts.LabelOpts(is_show=True, formatter='{b}'))
-
# 自定义分段 color 可以用取色器取色
-
pieces = [
-
{'min': 110, 'max': 111, 'label': '幼儿园', 'color': '#FF0000'}, # 红色
-
{'min': 210, 'max': 211, 'label': '小学', 'color': '#FF8C00'}, # 橙色
-
{'min': 217, 'max': 218, 'label': '小学教学点', 'color': '#FF8C66'}, # 橙色
-
{'min': 310, 'max': 311, 'label': '初级中学', 'color': '#00CED1'}, # 绿色
-
{'min': 312, 'max': 313, 'label': '九年一贯制', 'color': '#55CED1'}, # 绿色
-
{'min': 340, 'max': 341, 'label': '完全中学', 'color': '#99CED2'}, # 绿色
-
{'min': 342, 'max': 343, 'label': '高级中学', 'color': '#22CED6'}, # 绿色
-
{'min': 363, 'max': 364, 'label': '职业高中', 'color': '#2200FF'},
-
{'min': 512, 'max': 514, 'label': '特殊教育', 'color': '#0066FF'},
-
{'min': 410, 'max': 415, 'label': '高等学校', 'color': '#6600FF'} # 蓝色
-
]
-
# is_piecewise 是否自定义分段, 变为true 才能生效
-
g.set_global_opts(
-
visualmap_opts=opts.VisualMapOpts(is_piecewise=True, pieces=pieces),
-
title_opts=opts.TitleOpts(title="{}-学校分布".format(city)), )
-
-
# g = test_geo()
-
# 渲染成html, 可用浏览器直接打开
-
g.render_notebook()
-
g.render("a.html")
-
-
mapa()
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhekkbkk
系列文章
更多
同类精品
更多
-
photoshop保存的图片太大微信发不了怎么办
PHP中文网 06-15 -
Android 11 保存文件到外部存储,并分享文件
Luke 10-12 -
《学习通》视频自动暂停处理方法
HelloWorld317 07-05 -
word里面弄一个表格后上面的标题会跑到下面怎么办
PHP中文网 06-20 -
photoshop扩展功能面板显示灰色怎么办
PHP中文网 06-14 -
微信公众号没有声音提示怎么办
PHP中文网 03-31 -
excel下划线不显示怎么办
PHP中文网 06-23 -
excel打印预览压线压字怎么办
PHP中文网 06-22 -
怎样阻止微信小程序自动打开
PHP中文网 06-13 -
TikTok加速器哪个好免费的TK加速器推荐
TK小达人 10-01