Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
edwardoughton opened this issue Feb 20, 2022 · 0 comments

Comments

@edwardoughton
Copy link

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant