0

How to set margins of output figure please?

plt.rcParams["figure.figsize"] = [9, 4]
plt.savefig('figure.pdf')

I would like to have minimal white place to top and bottom margins. In the scrip, I remove axes, can it be the problem?

plt.xticks([]) 
plt.yticks([])
ax.xaxis.set_ticks_position('none') 
ax.yaxis.set_ticks_position('none')

1 Answer 1

2

Check out tight_layout().

import matplotlib.pyplot as plt


plt.plot([1, 5, 3])
ax = plt.gca()

plt.xticks([])
plt.yticks([])
ax.xaxis.set_ticks_position('none')
ax.yaxis.set_ticks_position('none')

plt.rcParams["figure.figsize"] = [9, 4]
plt.tight_layout(pad=0)
plt.savefig('figure.pdf')

example of tight_layout()

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

Comments

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.