Issue
If I add a subtitle to my matplotlib figure it gets overlaid by the subplot's titles. Does anybody know how to easily take care of that? I tried the tight_layout()
function, but it only makes things worse.
Example:
import numpy as np
import matplotlib.pyplot as plt
f = np.random.random(100)
g = np.random.random(100)
fig = plt.figure()
fig.suptitle('Long Suptitle', fontsize=24)
plt.subplot(121)
plt.plot(f)
plt.title('Very Long Title 1', fontsize=20)
plt.subplot(122)
plt.plot(g)
plt.title('Very Long Title 2', fontsize=20)
plt.tight_layout()
plt.show()
Solution
You can adjust the subplot geometry in the very tight_layout
call as follows:
fig.tight_layout(rect=[0, 0.03, 1, 0.95])
As it's stated in the documentation (https://matplotlib.org/users/tight_layout_guide.html):
tight_layout()
only considers ticklabels, axis labels, and titles. Thus, other artists may be clipped and also may overlap.
Answered By - soupault
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.