Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 509
user1187727 Avatar asked Aug 28 '26 22:08

user1187727


2 Answers

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

like image 192
Pablo Navarro Avatar answered Aug 30 '26 11:08

Pablo Navarro


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

like image 38
Erik Schomburg Avatar answered Aug 30 '26 11:08

Erik Schomburg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!