10

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!

2
  • How do you imagine us helping you without seeing the code that produced this figure? Commented Oct 23, 2016 at 7:20
  • Sorry! I added the code Commented Oct 23, 2016 at 7:28

3 Answers 3

12

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.

Sign up to request clarification or add additional context in comments.

Comments

10

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!

Comments

2

You can use the axes() command that allows you to specify the location as axes. You can also use the xlim() command and ylim() command. In your case, you can use the latter. So just as an example, the xlim method can be used like this:

plt.xlim(X.min()*1.1, X.max()*1.1)
plt.ylim(C.min()*1.1, C.max()*1.1)

This will make some space for the data points to be seen clearly. Hope that helps. Just seen the code so you're using xlim method. You want to create the subplot somewhere else, for that you can use the axis() method.

plt.axes([0.3, 0.3, .5, .5])

You can adjust plot accordingly. This one will create a subplot in the upper right corner of the figure.

3 Comments

Please add the meaning of the 4 values in the axes() rect definition
Thank you very much! I just found the comand "plt.tight_layout()" --> what do you think about that?
@Matias It seems to be exactly what you need. Why don't you self-answer your question?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.