Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Adding white space around plot in Matplotlib

I have a figure with a fixed size and want to change the size of the plot inside it, i.e., add white space around it. Most questions online deal with removing white space or subplots, which I don’t have.

My plotting code is

fig = plt.figure(figsize=(14,10))
plt.plot(n, y)
plt.savefig('figure.png', bbox_inches='tight', dpi=200)

so really nothing special. I already tried margins and tight_layout(pad = X) but nothing worked.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can adjust the subplot parameters using subplots_adjust

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(14, 10))
plt.plot(n, y)

#Adjust the subplot parameters to add white space
plt.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)

plt.savefig('figure.png', dpi=200)

by adjusting the values for left, right, top, and bottom, you can control the amount of white space added around the plot.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading