如何减少 Python 图中的空格?

How can I reduce whitespace in Python plot?

我正在使用它绘制 2 个 shapefile(转换为 geopandas 数据框)。但是空格太多了。我怎样才能减少它以用地图更多地填充框? xlimylim 似乎没有任何影响

f, ax = plt.subplots(1, figsize=(8, 8))
polydatx.plot(ax = ax, column = 'Elev_Avg', cmap='OrRd', scheme='quantiles')
segdatx.plot(ax = ax)
ax.grid(False)
ax.set_ylim(47, 47.3)
plt.axis('equal');

问题出在调用

plt.axis('equal')

设置新的ylim后。

来自docs

axis('equal') changes limits of x or y axis so that equal increments of x and y have the same length; a circle is circular.:

axis('scaled') achieves the same result by changing the dimensions of the plot box instead of the axis data limits.

在你的情况下,我会将图形大小调整为某个矩形,而不是正方形,并使用 axis('scaled')