参考:geopandas.GeoDataFrame.plot
参考:geopandas,用python分析地理空间数据原来这么简单!
1. 基本地图显示
import pandas as pd
import geopandas
import matplotlib.pyplot as plt
%matplotlib inline
world = geopandas.read_file(geopandas.datasets.get_path('naturalearth_lowres'))
# 加上末尾的分号,不会先是某行文字
world.plot(figsize=(20,10));
2. 显示地图边界线
world.boundary.plot(figsize=(20,10))
3. 专题地图显示
- 属性对应的列
- 选择地图的颜色模式
- 显示大小
- 边界颜色
# remove the record of Antarctica
world = world[(world.pop_est>0) & (world.name!="Antarctica")]
# add a new column "gdp_per_cap"
world['gdp_per_cap'] = world.gdp_md_est / world.pop_est
# show the world map based on "gdp_per_cap", different colors, with black edge
world.plot(column='gdp_per_cap', cmap='OrRd', figsize=(20,10), edgecolor="black");
4. 专题地图加入图例
# Plot population estimates with an accurate legend
import matplotlib.pyplot as plt
fig, ax = plt.subplots(1, 1, figsize=(20,12))
world.plot(column='gdp_per_cap',
ax=ax,
cmap='OrRd',
edgecolor='black',
legend=True,
legend_kwds={'label': "GDP per capita by Country", 'orientation': "horizontal"});
fig, ax = plt.subplots(1, 1, figsize=(20,6))
world.plot(column='gdp_per_cap',
ax=ax,
cmap='OrRd',
edgecolor='black',
legend=True,
legend_kwds={'label': "GDP per capita by Country", 'orientation': "vertical"});
5. 多图层显示
cities = geopandas.read_file(geopandas.datasets.get_path('naturalearth_cities'))
base = world.plot(color='#CCFFE5', edgecolor='black', figsize=(20,8))
cities.plot(ax=base, marker='o', color='red', markersize=10);
标签:gdp,plot,GeoPandas,per,ax,绘图,geopandas,world,822 From: https://www.cnblogs.com/alex-bn-lee/p/17218663.html