Lukáš Altman
Lukáš Altman

Reputation: 527

Python - space for xlabels

How to set space for xlabels please? I read https://matplotlib.org/api/_as_gen/matplotlib.pyplot.xlabel.html but I don't understant. I use matplotlib.pyplot. Thank you

plt.xlabel(r'Měsíc', fontsize=12)

enter image description here

Upvotes: 1

Views: 80

Answers (1)

SpghttCd
SpghttCd

Reputation: 10880

You could use plt.tight_layout() it is used for exactly such problems. Additionally if its automatic algorithm to distribute everything nicely on the canvas, it as a kwarg rect, which needs a list of [xmin, ymin, xmax, ymax] values defining the space of the figure to be used for the (sub)plot(s), e.g.

plt.tight_layout(rect=[0, .1, 1, .95)

It should be called at the end of the plot creation, right before plt.show() if your script needs the latter.

Upvotes: 2

Related Questions