简体   繁体   English

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

[英]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.我需要创建一个包含 2 列子图的图形,其中第一个子图显示“正常”(非空间)plot,第二个是 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.在下图中,我想调整左侧 plot 的高度以适合右侧 map 的高度。

正常图和地图子图

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.我猜子图可能已经是相同的大小,但是正如您所看到的,左侧 plot 的边框比 map 的边框大,我希望它的高度与右侧的相同.

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:但是,如果我需要使用figsize调整图形大小,这将“破坏” map 比例,因此我调整图形大小以保留其比例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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