Automatic adjustment of a subplot Python

Question:

I am implementing an algorithme with Python and I would like to plot 2 subplots.

This is what I obtain:

enter image description here

I would like to know if there is a way to automaticaly adjust the space between the two plots to see the title & the xlabel?

Thanks

I don’t know how to do it.

Asked By: Dylan Chevalier

||

Answers:

You have to use plt.tight_layout:

fig, (ax1, ax2) = plt.subplots(nrows=2, ncols=1)
ax1.plot(arr.real)
ax1.set_title('Real part at the output of the filter')
ax2.plot(arr.imag)
ax2.set_title('Imaginary part at the output of the filter')
plt.tight_layout()
plt.show()

With plt.tight_layout:

enter image description here

Without plt.tight_layout:

enter image description here

Answered By: Corralien
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.