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.

6
  • possible duplicate of scipy: savefig without frames, axes, only content Commented Oct 6, 2012 at 22:36
  • If fig is the figure you create, does fig.patch.set_alpha(0.0) help? Commented Oct 6, 2012 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). Commented Oct 7, 2012 at 0:40
  • 1
    There does not appear to have to be a background colour of any sort: fig.set_facecolor('None') works fine. Commented Oct 8, 2012 at 13:36
  • fig.set_facecolor('None') does not remove this area ! Neither fig.patch.set_alpha(0.0)..! Commented Oct 8, 2012 at 20:02

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

3 Comments

It reduce it a bit. But it's still quite large for my contern...No way to remove it completely of the window ?
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 !
Can you post your code or a similar code? Maybe a image of what you want can help too.
1

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.