Basemap Shapefile visualizing

∥☆過路亽.° 提交于 2019-12-01 12:50:03

I recently wrote a blog post on making maps with Basemap and in it I use a shapefile to draw and colour in postcode areas in England and Wales. It might be of some help. http://www.jamalmoir.com/2016/06/creating-map-visualisations-in-python.html

Basically you can create a PatchCollection using your shapefile and then colour the PatchCollection in. Then you add that to your map and Bob's your uncle.

m.readshapefile('data/uk_postcode_bounds/Areas', 'areas')

df_poly = pd.DataFrame({
        'shapes': [Polygon(np.array(shape), True) for shape in m.areas],
        'area': [area['name'] for area in m.areas_info]
    })
df_poly = df_poly.merge(new_areas, on='area', how='left')

cmap = plt.get_cmap('Oranges')   
pc = PatchCollection(df_poly.shapes, zorder=2)
norm = Normalize()

pc.set_facecolor(cmap(norm(df_poly['count'].fillna(0).values)))
ax.add_collection(pc)

In this example I use the count of new houses to colour each area but you can do what you like.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!