frameon=False shifts plot axes to to the right and increases figure width #1586

pmacaodh opened this Issue Dec 11, 2012 · 8 comments

4 participants


The frameon argument shifts the plot axes to the right leaving a strip of blank canvas to the left of the plot axes, while increasing the figure's width. Altogether, a highly undesirable side-effect.

ax.legend('test', frameon=False)

I'm using 1.2.0rc3

A search for frameon in issues produced nothing describing this problem. A wider google search uncovered a couple of references to this problem but the solution still eludes me.

Matplotlib Developers member

I can't recreate this with the OS X or Qt4Agg backends. I also can't recreate it saving a png from Agg. All this is using master, which is currently at dc1d0ee.

I can't recreate this with OS X or Qt4Agg backends on the current v1.2.x tip, which is currently at da2d0c4.

I also can't recreate this with OS X or Qt4Agg on v1.2.0rc3.

Could you provide a little more information about your backend? And perhaps add a screen shot of the behaviour you are seeing? GitHub now allows you to drag an image into the comment box to attach it.

Thanks for reporting the problem, @pmacaodh.


I'm using the pylab backend in ipython:

Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)]
IPython -- An enhanced Interactive Python.

Welcome to pylab, a matplotlib-based Python environment [backend: module://IPython.zmq.pylab.backend_inline].


Hope that can help you track it down. Thanks for you efforts!

Matplotlib Developers member

The issue is with bbox_inches='tight which ipython uses in the inline backend.
The bounding box of the legend is only calculated when the frame is on. I have
a pull request fixing this shortly.

Matplotlib Developers member

@pmacaodh Do you have the possibility to test the attached pull request?

Matplotlib Developers member

By the way. This code illustrates the issue: (toggling between True and False

fig = plt.figure()
ax = fig.add_subplot(1,1,1)
l = ax.legend('test', frameon=True)
print l.get_window_extent(fig._cachedRenderer)
print l._legend_box.get_window_extent(fig._cachedRenderer)

@jenshnielsen I'm afraid I don't have the possibility to test the pull request - I'm not so proficient in these development tools.

Thanks for your efforts. I trust the fix will appear in the main code base soon so I'll hold tight until then.

Matplotlib Developers member

@jenshnielsen If I am reading this thread correctly you think this if fixed. If I am incorrect please re-open.

@tacaswell tacaswell closed this Jan 17, 2014
Matplotlib Developers member

yes this should be fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment