Problem with matplotlib and pdflatex

Alex Coventry <throwaway@...1165...> writes:

I'm trying to use some matplotlib-generated pdfs in a pdflatex document,
and seeing some extremely weird and disruptive size effects.

Could you be more specific about what the problem seems to be? I looked
at your pdf files, and it looks like pdflatex is taking your eight-inch
wide figure (including the margins) and scaling it to 6 in. The space
between the margins is about 4.8 in, so of course the figure doesn't
fit, and because it has empty margins on every side, it kind of looks
like it has been translated away from where it belongs. If this is not
what you are seeing, could you post a screenshot from your pdf viewer?

Do you mean to ask how you can make the figure take up exactly the space
between the margins in your document? In that case my recommendation is
to build up the figure to the correct width from the start, e.g.
figure(figsize=(4.8,4.8)) or whatever the correct size is, and avoid
doing any kind of resizing with \includegraphics. Create your axes
explicitly instead of relying on the default (which reserves ample
margins on every side in case you want to put a title on top, etc).
Start with something like axes([0.1,0.1,0.9,0.9]) -- the numbers are
left, bottom, width, height, so to remove the margin on the right make
sure left+width=1.0. You will have to tweak this to make just enough
room for your axis labels.

If I generate postscript files with matplotlib and convert
them to pdfs, I don't get this problem.

Probably some step in this pipeline recomputes the bounding box for the
figure from the ink on the page, so the margins disappear.

···

--
Jouni K. Sepp�nen
http://www.iki.fi/jks