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
  • 4,170
  • 12
  • 37
  • 53
Laurits L. L.
  • 417
  • 1
  • 4
  • 15

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,400
  • 9
  • 16
1

Add

plt.tight_layout()

after the plot command

Sheldore
  • 37,862
  • 7
  • 57
  • 71
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
  • 467
  • 1
  • 3
  • 15