Problems with bbox_inches='tight' #1135

pwuertz opened this Issue Aug 22, 2012 · 5 comments


None yet

2 participants


If I understood the method correctly, tight_bbox causes a figure to be printed to a in-memory buffer first, determines the bounding box of the figure contents and saves a new figure shrunk to the extent of the contents. Right?

Tight_bbox seems to have trouble figuring out the bounding box of a PDF created with latex using the pgf backend. This example produces a PNG and a PDF to be clipped with tight_bbox (make sure you are using the current master). The PNG is clipped correctly, the bounding box of the PDF is estimated incorrectly however.

import matplotlib as mpl
import matplotlib.pyplot as plt

plt.plot(range(5), markersize=2, marker='x')

plt.savefig('test.pdf', bbox_inches='tight')
plt.savefig('test.png', bbox_inches='tight')

I don't know exactly how tight_bbox works, or why it doesn't just calculate the figure's extent in the same way tight_layout solves that issue instead.

Matplotlib Developers member

I'm marking this with the 1.2 milestone, because it would be nice to have this resolved for the release when many people are likely to try the new awesome PGF backend. We can let this slide if the solution turns out to be tricky.


Hm.. what is the kwarg bbox_inches_restore supposed to do? It is given to me at the second pass of print_pdf.. I'm getting some bounding box and a function..

@pwuertz pwuertz closed this Aug 22, 2012

I think I found the reason for this. Let's continue here:

@pwuertz pwuertz reopened this Aug 22, 2012

Workaround for matplotlib 1.2 release

Matplotlib Developers member

I'm closing this because I understand #1155 resolves it (at least insofar as a temporary solution for 1.2.x). Please reopen if I'm mistaken.

@mdboom mdboom closed this Aug 28, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment