geopandas / contextily

Context geo-tiles in Python
https://contextily.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
493 stars 81 forks source link

Using contextily adds blank space to the right of a matplotlib panel plot #198

Open edwardoughton opened 2 years ago

edwardoughton commented 2 years ago

I recently posted this stackoverflow question due to an error that is (i think) being produced by contextily:

https://gis.stackexchange.com/questions/424324/contextily-adds-blank-space-to-the-right-of-matplotlib-panel-plot

Here's the reproducible example:

import geopandas as gpd
import matplotlib.pyplot as plt
import contextily as cx  

fig, (ax1, ax2) = plt.subplots(2, 2, figsize=(8,8))
fig.subplots_adjust(hspace=.2, wspace=.2)
fig.set_facecolor('lightgrey')

geom = [{
    'type':'Feature',
    'geometry': {
        'type': 'Polygon',
        'coordinates': [[
            [2.0,7.0],[2.0,8.0],[3.0,8.0],[3.0,7.0]
        ]],
    },
    'properties': {}
}]

geo_df = gpd.GeoDataFrame.from_features(geom)

geo_df.plot(facecolor="none", edgecolor="grey", ax=ax1[0])
geo_df.plot(facecolor="none", edgecolor="grey", ax=ax1[1])
geo_df.plot(facecolor="none", edgecolor="grey", ax=ax2[0])
geo_df.plot(facecolor="none", edgecolor="grey", ax=ax2[1])

# crs = 'epsg:4326'
# cx.add_basemap(ax1[0], crs=crs)
# cx.add_basemap(ax1[1], crs=crs)
# cx.add_basemap(ax2[0], crs=crs)
# cx.add_basemap(ax2[1], crs=crs)

plt.savefig('my_figure.png',
pad_inches=0.4,
bbox_inches='tight'
)
plt.close()

If anyone could advise why this might be happening, I would appreciate it!

Thanks!