Matplotlib - How to strip extra whitespaces from a plot without needing to save it?

Viewed 85

I have made a plot, and I don't want extra whitespaces in my plot; the question is:

How can I strip extra whitespaces from a plot?

I know you can strip extra whitespaces from a plot when you save it; Then you just do this: plt.savefig('file_name.png', bbox_inches='tight')

But I can't find any similar arguments you can pass to plt.plot() to have no extra whitespaces. Is it possible to pass an argument to plt.plot()?

3 Answers

Add

plt.tight_layout()

after the plot command

The easiest way imho is to click on the button "configure subplots" and adjust the sliders because you see the result immediately. You could although call the tight_layout() function directly on plt bevor show()

Related