3

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.

user1187727
  • 409
  • 2
  • 9
  • 19
  • possible duplicate of [scipy: savefig without frames, axes, only content](http://stackoverflow.com/questions/8218608/scipy-savefig-without-frames-axes-only-content) – unutbu Oct 06 '12 at 22:36
  • If `fig` is the figure you create, does `fig.patch.set_alpha(0.0)` help? – halex Oct 06 '12 at 22:43
  • 2
    If you're talking about saving the figure with a transparent background, see @unutbu's comment. Otherwise, there has to be a background color of some sort. You can set it with `fig.set_facecolor('white')` (or whatever other color you'd like). – Joe Kington Oct 07 '12 at 00:40
  • 1
    There does not appear to have to be a background colour of any sort: fig.set_facecolor('None') works fine. – Daan Oct 08 '12 at 13:36
  • fig.set_facecolor('None') does not remove this area ! Neither fig.patch.set_alpha(0.0)..! – user1187727 Oct 08 '12 at 20:02
  • True, but you want `'none'`, not `'None'` for what it's worth. And it's still a background color, it's just the background color of the window. (Thus my comment earlier about there still being a background color. I was being overly pedantic and not helpful, though.) – Joe Kington Oct 11 '12 at 01:22

2 Answers2

1

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

Pablo Navarro
  • 8,244
  • 2
  • 43
  • 52
  • 1
    It reduce it a bit. But it's still quite large for my contern...No way to remove it completely of the window ? – user1187727 Oct 08 '12 at 19:52
  • It reduce it a bit on the right side but I lose the centering of the display in the figure. It also make the zoom_rect tools unstabling the figure size and display position within... strange ! – user1187727 Oct 10 '12 at 09:12
  • Can you post your code or a similar code? Maybe a image of what you want can help too. – Pablo Navarro Oct 10 '12 at 13:53
1

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