小编HeL*_*889的帖子

matplotlib ax 到图形范围 - 删除空白、边框、geopandas 地图绘图的所有内容

我正在寻找一种使用 matplotlib 进行无缝地图图像绘制的解决方案。当前的代码运行良好且稳定,但是,它在左侧和底部留下了空白。我想删除这个空白,但不知道如何。

我的示例代码:

import geopandas
from seaborn import despine
from pandas import read_csv
import matplotlib.pyplot as plt

# read data and shapefile
geo_path = 'shapefiles/ne_10m_admin_0_countries.shp'
df = read_csv('UNpopEstimates2100.csv')
world = geopandas.read_file(geo_path)

# specifiy what is to be plotted
cm = 'Greys'
world['2015'] = df['2015']

# set plot environment
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1])
ax.axis('off')
plt.subplots_adjust(left=0, right=1, bottom=0, top=1)

world.plot(ax=ax, column='2015', cmap=cm, scheme='quantiles')

plt.savefig('sample.png', bbox_inches='tight', tight_layout=True, pad_inches=0, frameon=None)
Run Code Online (Sandbox Code Playgroud)

样本.png

我想删除带有标记空白的 smaple.png

我遵循了Matplotlib's Tight Layout Guide、 …

python plot matplotlib removing-whitespace geopandas

1
推荐指数
1
解决办法
5932
查看次数