2016-03-05 63 views
-1

对于我的蟒蛇知识水平来说,这可能是一项潜在的不可能的任务,但我一直在考虑是否有一种方法(可能是现有的程序)来映射数据框的结果, AreaCodes列和Test Results列,放到地区的实际地图上。将结果绘制到大熊猫的实际地图上

所以我DF看起来是这样的:

  PostCode Area Test Result 
0     BN   P 
1     PE   P 
2     SO   PRS 
3     PE   P 
4     PE   F 
5     CW   P 
6     CW   F 
7     S   P 
8     S   F 
9     SW   P 
10     SW   F 
11     CM   P 
12     CM   F 

而且邮编地区是英国。我正在寻找类似于英国的热图的东西,其强度由'P's'计数控制。

回答

0

您可以使用cartopy进行此操作。

pip install https://github.com/SciTools/cartopy/archive/v0.13.1.tar.gz 

你需要GEOS,身材匀称UND proj4,这是最容易使用水蟒:

conda install geos proj4 shapely 

我下载从这里包含英国邮政领域的形状文件: http://www.opendoorlogistics.com/downloads/

你可以然后使用cartopy颜色这样的区域:

from cartopy import crs 
from cartopy.io import shapereader 

import matplotlib.pyplot as plt 
from matplotlib.cm import get_cmap 

cmap = get_cmap('viridis') 

uk_postal_areas = shapereader.Reader('Areas.shp') 

ax = plt.axes(projection=crs.Mercator()) 

values = { 
    'BA': 0.5, 
    'BN': 0.1, 
    'NE': 1.0, 
    'IV': 0.7, 
    'BT': 0.3, 
} 

for record in uk_postal_areas.records(): 
    name = record.attributes['name'] 
    ax.add_geometries(
      [record.geometry], 
      facecolor=cmap(values.get(name, 0)), 
      linewidth=0, 
      crs=crs.PlateCarree(), 
    ) 

ax.set_extent([-10, 4, 48, 61], crs=crs.PlateCarree()) 

plt.show() 

结果

result

+0

谢谢,但我不断收到此错误:命令 “蟒蛇setup.py egg_info” 在C失败,错误代码1:\ USERS \ eduar \应用程序数据\本地\ TEMP \ PIP-zluvvv-建立\ - 安装cartopy时 –