简体   繁体   中英

Adjust plot height to map height when plotting matplotlib plot and geopandas map side by side

I need to create a figure with 2 columns subplots, where the first subplot display a "normal" (non-spatial) plot, and the second is a map.

They should be side by side and I would need them to have the same height.

In the figure below, I'd like to adjust the height of the plot on the left to fit the height of the map on the right.

正常图和地图子图

I guess the subplots might already be the same size, but as you can see, the border of the plot on the left is bigger than that of the map, and I'd like its height to be the same as the one on the right.

The code I am running is this one.

import numpy as np

fig, (ax1, ax2) = plt.subplots(ncols=2)

ax1.plot(np.arange(10))
gdf.plot(ax=ax2)

Solution found here !

fig.subplots_adjust(hspace=0.0, wspace=0.0)

等高的子图

However , if I need to adjust the figure size with figsize , this would "break" the map proportion, so I resize the figure preserving its ratio with:

RESIZE_FACTOR = 2.5
fig.set_size_inches(fig.get_size_inches()*RESIZE_FACTOR)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM