简体   繁体   中英

X-axis Label Gets Cut Off Of Graph - Python Matplotlib

I have in my python script this

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

在此处输入图片说明

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?

Thanks

Either use:

plt.tight_layout()

or specifically set the margins, eg 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:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM