user1187727
user1187727

Reputation: 419

Remove grey background borders in matplotlib figure

I want to display only the plot graphic (or imshow) in matplotlib figure. I can remove the axis with pylab.axis('off') but I still have some grey borders in the figureenter image description here

I give an example. I want to remove all and only keep the imshow domain (and keep the zoom available).

Many thanks.

Upvotes: 3

Views: 5541

Answers (2)

Erik Schomburg
Erik Schomburg

Reputation: 11

Try the margins() function (also an axis method): http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.margins

Upvotes: 1

Pablo Navarro
Pablo Navarro

Reputation: 8264

In your case, you may want to reshape the figure window in order to fit the content's shape. For a squared window you can use:

fig = figure(figsize=(6, 6))  # width and height in inches
fig.tight_layout(pad=0.5)     # distance betweeen the axis and the figure edge 

Make sure to keep some space for the axis labels, if you need them. If you want just to change the background color, the comment of @JoeKington is the answer.

http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.tight_layout

Upvotes: 1

Related Questions