2

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()?

colidyre
  • 3,401
  • 11
  • 33
  • 47
Laurits L. L.
  • 420
  • 1
  • 4
  • 14

3 Answers3

3

Have a look here: Reduce left and right margins in matplotlib plot

Couple of options you can use:

plt.tight_layout()

plt.subplots_adjust(left=0.1, right=0.9, top=0.9, bottom=0.1)

Piotrek
  • 1,290
  • 8
  • 15
1

Add

plt.tight_layout()

after the plot command

Sheldore
  • 35,129
  • 6
  • 43
  • 58
1

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()

Sebastian E
  • 339
  • 1
  • 2
  • 14