5

I have in my python script this

import matplotlib.pyplot as plt

date_list = ["01/11/2015", "01/12/2015", "01/13/2015", "01/14/2015"]
plt.plot([1,2,3,4], [2,4,6,8])
plt.xticks([1,2,3,4], date_list)
locs, labels = plt.xticks()
plt.setp(labels, rotation=45)
plt.savefig('test.pdf')

And it produced a graph that looks like this

enter image description here

As you can see the x label get cut off and this is not me not fully expanding the graph, I have tried that and it is still cut off. How can I get the whole label on the graph?

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
spen123
  • 3,464
  • 11
  • 39
  • 52

1 Answers1

13

Either use:

plt.tight_layout()

or specifically set the margins, e.g. using subplots_adjust():

subplots_adjust(left=None, bottom=None, right=None, top=None, wspace=None, hspace=None)

The first solution with your example results in:

enter image description here

Bart
  • 9,825
  • 5
  • 47
  • 73
  • 1
    `plt.tight_layout()` do the job for me, there is also `pad` argument which can be used to add margin – pplonski Apr 15 '20 at 14:05