Matplotlib projection remove margin

坚强是说给别人听的谎言 提交于 2019-12-20 05:14:57

问题


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())

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())

And then this happened:

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.

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?


回答1:


You can use subplots_adjust:

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

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

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



来源:https://stackoverflow.com/questions/39410665/matplotlib-projection-remove-margin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!