使用python绘制地图,除了basemap这个library外,还有folium
这个包,提供了leaflet.js 库的python接口,下面简单介绍一下,官方详细例程在https://github.com/python-visualization/folium/tree/master/examples
(1)支持的地图样式:OpenStreetMap(默认), Stamen Terrain, Stamen Toner, Mapbox Bright, and Mapbox Control Room,mapbox需要提供API
(2)支持的标记:默认,圆形,正方形,以及使用folium.GeoJson构建的自定义形状
(3)popup弹出内容:自定义的文本内容,经纬度,html内容,json(表格)内容
更多关于popup的内容可以访问http://nbviewer.jupyter.org/github/python-visualization/folium/blob/master/examples/Popups.ipynb
# -*- coding: utf-8 -*-
"""
Created on Sat Dec 23 19:25:07 2017
@author: kindy
"""
import folium
import webbrowser
import json
import os
import pandas as pd
df = pd.DataFrame(data=[['apple', 'oranges'], ['other', 'stuff']], columns=['cats', 'dogs'])
os.chdir(r"D:\Files\python\地图")
#vis1 = "vis1.json"
#html = df.to_html(classes='table table-striped table-hover table-condensed table-responsive')
html = df.to_html()
m = folium.Map(
location=[23.1596,113.3486],
zoom_start=7,
tiles='Stamen Terrain' #更改了展开图样式
)
folium.Marker(
location=[23.1596,113.3486],
popup=folium.Popup(html,max_width=450)).add_to(m)
file_path = r"D:\Files\python\地图\marker_chart.html"
m.save(file_path)
webbrowser.open(file_path)