Matplotlib Toolkits:地图绘制工具

Matplotlib Toolkits:地图绘制工具 

有没有一种可以直接在详细地图(如谷歌地图)上绘制上百万坐标点的工具???谷歌地图坐标点多了也不能绘制了。

Basemap

(Not distributed with matplotlib,要手动安装)

Plots data on map projections, with continental and political boundaries, see basemap docs.

安装

先下载anacondaPython 3版本

conda install -c scitools basemap

[Installing¶]

使用

分辨率设置

if resolution == 'c':
    area_thresh = 10000.
elif resolution == 'l':
    area_thresh = 1000.
elif resolution == 'i':
    area_thresh = 100.
elif resolution == 'h':
    area_thresh = 10.
elif resolution == 'f':
    area_thresh = 1.

[basemap]

[地理信息可视化——Python之matplotlib Basemap简介]

[So You’d Like To Make a Map Using Python ]

静态地图示例

# coding=utf8
import os
import sys

import matplotlib.pyplot as plt
import pandas as pd

CWD = os.path.split(os.path.realpath(__file__))[0]
os.makedirs(os.path.join(CWD, 'middlewares'), exist_ok=True)
sys.path.append(os.path.join(CWD, '../../..'))

df = pd.read_pickle(os.path.join(CWD, 'middlewares/df.pkl'))  # ca datasets
ll = df[['longitude', 'latitude']].values
print(len(ll))
x, y = ll[:, 0], ll[:, 1]

from mpl_toolkits.basemap import Basemap

# 建一用于制。我使用的是墨托投影,并显示整世界。
m = Basemap(projection='merc', llcrnrlat=-50, urcrnrlat=65, llcrnrlon=-165, urcrnrlon=155, lat_ts=20, resolution='c')
# 制海岸线,以及地边缘
m.drawcoastlines()
m.drawmapboundary()
m.drawcountries()
m.drawstates()
m.drawcounties()
x, y = m(y, x)
m.scatter(x, y, 1, marker='.', color='r')
plt.show()
Matplotlib Toolkits:地图绘制工具_第1张图片

Debug

m.drawcounties() UnicodeDecodeError: 'utf-8' codec can't decode byte 0xf1 in position 2: invalid continuation byte

解决:shapefile.py源码有错:修改编码为latin-1就可以了,也是醉了。。。

return v.decode('latin-1')
# return v.decode('utf-8')

[[译]比一比:Python的七个数据可视化工具 静态地图]

皮皮blog


Cartopy

评价:安装麻烦,map功能也不能使用了,估计开发者也抛弃了。。。真是跪了。。。lz已弃用

(Not distributed with matplotlib)

Cartopy is a Python package designed to make drawing maps for data analysis and visualisation as easy as possible.

Cartopy makes use of the powerful PROJ.4, numpy and shapely libraries and has a simple and intuitivedrawing interface to matplotlib for creating publication quality maps.

Some of the key features of cartopy are:

  • object oriented projection definitions
  • point, line, vector, polygon and image transformations between projections
  • integration to expose advanced mapping in matplotlib with a simple and intuitive interface
  • powerful vector data handling by integrating shapefile reading with Shapely capabilities

An alternative mapping library written for matplotlib v1.2 and beyond.Cartopy builds on top ofmatplotlib to provide object oriented map projection definitions and closeintegration with Shapely for powerful yet easy-to-use vector data processingtools.

Note: shapely,是geos的python封装,而geos是jts的c++移植版本。[python地理数据处理库geopy ]

安装

先下载anacondaPython 3版本

conda install -c scitools cartopy

[Installing Cartopy¶]

下载配角:地图数据
下载地址:http://www.naturalearthdata.com/downloads/
里面有三种分辨率的shape地图数据可选,方便起见,分别下载三种分辨率中的physical数据中的Coastline和Land数据,每种数据下载后都是一个压缩包,如下载了1:10分辨率的physical中的coastline数据压缩包:ne_10m_coastline.zip,解压缩后有6个文件,其中“ne_10m_coastline.README”和“ne_10m_coastline.VERSION”可直接删除,剩余4个,进行改名操作,扩展名前面的文件名,如“ne_10m_coastline”,修改为“10m_coastline”,即去掉“ne_”,4个文件分别这样更改。再下载1:50和1:110的文件分别进行此操作。所有地图文件下载、解压、更名完毕后,拷贝到一个文件夹下。我的文件夹列表如下图,把这些文件全选(注意进入文件夹目录,全选文件,不带文件夹),复制粘贴到D:\Program Files\WinPython-32bit-2.7.9.3\settings\.local\share\cartopy\shapefiles\natural_earth\physical 目录下(该目录根据自己所装的python而定,运行(1)中的程序后,程序会自动创建physical文件夹,具体该文件夹在哪,搜索电脑文件找找看),我安装的是winpython2.7.9.3,physical目录就位于上面这个目录中,所以我把所有shape地图文件拷贝到了该physical目录下。

[python绘制地图的利器Cartopy使用说明]

或者下载详细地图:http://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_1_states_provinces.zip解压到:c:\Users\《用户》.local\share\cartopy\shapefiles\natural_earth\cultural\

[cartopy_trial]

使用

最近不能使用map服务了:

As of July 11, 2016, direct tile access has been discontinued.Please visit our blog post for more information:http://goo.gl/xB0xXt

[Cartopy]

[examples: Cartopy gallery]

皮皮blog



谷歌地图python接口gmplot

10w以上数据坐标点绘制js就基本崩了不能用了。

Plotting data on Google Maps, the easy way. A matplotlib-likeinterface to generate the HTML and javascript to render all thedata you'd like on top of Google Maps. Several plotting methodsmake creating exploratory map views effortless.

# coding=utf8
import os
import sys

import pandas as pd

CWD = os.path.split(os.path.realpath(__file__))[0]
df = pd.read_pickle(os.path.join(CWD, 'middlewares/df.pkl'))  # ca datasets
ll = df[['longitude', 'latitude']].values
print(len(ll))
x, y = ll[:, 0], ll[:, 1]

import gmplot

gmap = gmplot.GoogleMapPlotter(37.428, -122.145, 5)
# gmap.plot(latitudes, longitudes, 'cornflowerblue', edge_width=10)
gmap.scatter(x, y, marker=False, c='r', size=2)
# gmap.heatmap(heat_lats, heat_lngs)
gmap.draw("map.html")

[gmplot]

高德地图amap python接口

1)读取文件信息,这里用pandas库以dataframe形式.

2)高德地图添加点有50数量限制,所以lz就直接弃用了。。。

3)将查询经纬度后的结果存为csv

[Python获取amap高德地图]

百度地图python接口

[mapapi > 0.2.1]

[python实现地址分布可视化]

[Baidu与Google地图API初探 ]

皮皮blog



其它工具

[使用地图工具,给出经纬度,画出受影响的中国省份,(比如台风经过的path、各省经济问题热点图。。。)]

from: Matplotlib Toolkits:地图绘制工具

ref: [Mapping Toolkits]


你可能感兴趣的:(Matplotlib小记)