Search code examples
matplotlibmargin

How do I extend the margin at the bottom of a figure in Matplotlib?


The following screenshot shows my x-axis.

enter image description here

I added some labels and rotated them by 90 degrees in order to better read them. However, pyplot truncates the bottom such that I'm not able to completely read the labels. How do I extend the bottom margin in order to see the complete labels?


Solution

  • Two retroactive ways:

    fig, ax = plt.subplots()
    # ...
    fig.tight_layout()
    

    Or

    fig.subplots_adjust(bottom=0.2) # or whatever
    

    Here's a subplots_adjust example: http://matplotlib.org/examples/pylab_examples/subplots_adjust.html

    (but I prefer tight_layout)