matplotlib axis('tight') doesn't work?

前端 未结 2 988
离开以前
离开以前 2021-01-14 00:05

According to the documentation, ax.autoscale(tight=True) should

If True, set view limits to data limits;

With ax.ax

2条回答
  •  粉色の甜心
    2021-01-14 00:55

    By setting the autoscale you should see the desired difference between tight=True and tight=False.

    f, (ax, ax2) = plt.subplots(ncols=2)
    
    ax.plot([0, 1], [1, 0], label="tight=True")
    ax.autoscale(enable=True, axis='both', tight=True)
    
    ax2.plot([0, 1], [1, 0], label="tight=False")
    ax2.autoscale(enable=True, axis='both', tight=False)
    
    ax.legend()
    ax2.legend()
    

    You may note that ax.axis("tight") is not related; it only states in the documentation that

    ‘tight’ Limits set such that all data is shown

    which is indeed the case, all data is shown (it doesn't say anything about setting the view limits to exactly the data).

提交回复
热议问题