Matplotlib投影删除边距 [英] Matplotlib projection remove margin

查看:35
本文介绍了Matplotlib投影删除边距的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是美国县的图像,创建于

Here's an image of US counties, created on top of

ax = plt.axes(projection=ccrs.LambertConformal())
ax.set_extent([-120, -70, 20, 50], ccrs.Geodetic())

在实时"图形中,可以使用 plt.show()看到图形周围有很大的灰色区域.在这里,您可以(不能)通过白色填充看到它.

In the "live" figure one can see with plt.show(), there's a large gray area around the figure. Here you can (not) see it via the white padding.

所以我想我可以再放大一点:

So I thought I could zoom in a bit more:

ax.set_extent([-120, -70, 20, 40], ccrs.Geodetic())

然后发生这种情况:

在图形周围仍然有白色边距/填充时,它突然被裁剪了.实时图像"还向我展示了一些明显位于投影周围的白色边缘.

While there is still white margin/padding around the figure, it's suddenly cropped. The "live image" also is showing me some white margin that is apparently placed around the projection.

我尝试了 plt.tight_layout(),它确实去除了大部分边距,但留下了一些(第二张图是在收紧布局后拍摄的).这种不可见的边距使得 ax.set_extent() 变得特别困难,因为在我可以扩展地图之前我看不到.

I tried plt.tight_layout(), which indeed removed much of the margins, but left some (the second picture is taken after tightening the layout). This invisible margin makes it especially difficult to ax.set_extent(), as I can't see until where I can extend the map.

有没有办法去除投影周围所有隐藏的填充/边距?

Is there some way to remove all the hidden padding/margin around the projection?

推荐答案

您可以使用subplots_adjust:

要删除 Axes 对象周围的所有空白,请使用:

To remove all the whitespace from around the Axes object, use:

fig.subplots_adjust(left=0, right=1, bottom=0, top=1)

设置 extent 是改变数据限制,而不是 Axes 的位置/大小.

Setting the extent is changing the data limits, not the position/size of the Axes.

这篇关于Matplotlib投影删除边距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆