Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matplotlib: change position of plot

I did the following plot with the figure size (which should not be changed):

plt.figure(figsize=(14, 5))

enter image description here

Unfortunately, the x-label is not fully visible. My question: Is it possible, to move the whole grafic to the top (because there would be enough space)?

The code:

plt.figure(figsize=(14, 5))
plt.plot(time_load,load, linewidth=1.5)
plt.grid(True)
plt.tick_params(labelsize=16)
plt.xlabel('Time [hours]',fontsize=16)
plt.xlim([0,24])
plt.xticks([0,4,8,12,16,20,24])
plt.legend(loc="upper left",fontsize = 'large')

Thank you very much for your help!

like image 821
Matias Avatar asked Dec 04 '22 23:12

Matias


2 Answers

A very simple approach is to use

plt.tight_layout()

See: http://matplotlib.org/users/tight_layout_guide.html

Thank you very much for your help!

like image 34
Matias Avatar answered Dec 06 '22 13:12

Matias


You can also try

plt.subplots_adjust(bottom=0.19)

If 0.19 adds too much or too little space to see the x-label better, then try adjusting little by little up or down.

like image 103
Daniel Goldfarb Avatar answered Dec 06 '22 12:12

Daniel Goldfarb