How can I move a tick label only(without moving corresponding tick)?

前端 未结 3 1911
暖寄归人
暖寄归人 2021-01-11 10:31

I\'m using matplotlib to generate a diagram, and I use set_ticks and set_ticklabels to mark out several important values on the x-axis. But some of

3条回答
  •  一个人的身影
    2021-01-11 11:06

    As a strict response to the question asked, you can get the specific tick and use set_pad()

    ax.get_xaxis().majorTicks[2].set_pad()
    

    I think that a better practice would be to use autofmt_xdate

    fig = plt.figure()
    fig.autofmt_xdate()
    

    Which rotates the xtick labels nicely and allow most texts to fit nicely without overlapping.
    If they still overlap - it means that those ticks are very close together. And then the question which arises is what good would two ticks so closely together would do to the viewer of your plot?

提交回复
热议问题