2016-06-01 138 views
12

我有一个情节是这样的:Matplotlib:紧定轴只有X或Y轴

enter image description here

显然,左侧和右侧是浪费空间,所以我设置

plt.axis('tight') 

但是这给了我剧情是这样的:

enter image description here

xlim现在看起来不错,但ylim对剧情太紧张了。

我想知道,如果我只能将axis(tight)只设置到x轴上?

所以情节可能是这个样子:

enter image description here

这当然是可能的,我可以做到这一点手动

plt.gca().set_xlim(left=-10, right=360) 

但恐怕这不是一个很优雅解。

回答

22

enter image description here

plt.autoscale(enable=True, axis='x', tight=True)

enter image description here

+1

加入少量的:我主要使用面向对象的API,'autoscale'实际上是'Axes'类的方法。 – Wisperwind