I am trying to find a method to remove the vertical white space from a figure generated and saved using matplotlib
. So, basically the white space above and below the axes.
The requiremens in my use case are the following:
- The y-axis may have a customized scaling which shall be preserved
- There may be a legend above the figure (on the outside) which shall not be cropped
- x- and y-axis do have labels which shall not be cropped as well
- Only the vertical white space shall be removed, not the horizontal. Otherwise, this would lead to an elongated x-axis.
The following command comes very close and removes the vertical white space, but it also removes the horizontal white space:
myFigure.savefig(myImagePath, bbox_inches='tight')
The optimal solution would be to apply the algorithm of bbox_inches='tight'
only to the y-axis of the plot...