How to change separation between tick labels and axis labels in Matplotlib

后端 未结 2 1764
旧巷少年郎
旧巷少年郎 2020-12-31 12:17

My axis labels often look not good (too close to tick labels) when I use Matplotlib.

\"test

How

2条回答
  •  耶瑟儿~
    2020-12-31 12:37

    This is a really subjective question, but I'll take a stab anyway:

    The figsize kwarg takes the width and height of the figure in inches.

    A4 paper is 8.3" by 11.7". So let's say, for the sake of argument, you want 1" margins.

    paperheight = 11.7
    paperwidth = 8.3
    margin = 1.0
    
    fig = plt.figure(figsize=(paperwidth - 2*margin, paperheight - 2*margin))
    
    # plotting stuff
    
    fig.tight_layout()
    fig.savefig(...)
    

    The call to tight_layout() will give the labels a bit more room and make sure that everything is expanded out to the figure edges as much as practicable.

提交回复
热议问题