From: Alex Coventry <throwaway@MIT.EDU> - 2008-03-21 22:27:44
I'm trying to use some matplotlib-generated pdfs in a pdflatex document,
and seeing some extremely weird and disruptive size effects. The
resulting pdfs can be seen at
The first results from the code
and the second from the same code with "width=5cm". The two pdfs I'm
trying to include are at
It doesn't matter what order I include them in, I get the same size
effects. If I generate postscript files with matplotlib and convert
them to pdfs, I don't get this problem. So I have a workaround, but I
would like to know how to create usable pdfs directly, and thought
reporting this might be useful to matplotlib development.
Alex Coventry <throwaway@...> 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
[I'm cc:ing the matplotlib-users list again.]
>> could you post a screenshot from your pdf viewer?
> I put some up at these URLs:
In the screenshots the problem is obvious. I didn't see it in either
Apple's Preview or Adobe Reader, but I do see it in xpdf. The problem is
that the graphics state stack is not always popped at the end of the
I believe I have fixed the problem in the latest svn versions, both on
the maintenance branch and on the trunk. Please try the latest version
with your code.
Jouni K. Seppänen
From: Alex Coventry <throwaway@MIT.EDU> - 2008-03-24 14:17:54
> I believe I have fixed the problem in the latest svn versions, both on
> the maintenance branch and on the trunk. Please try the latest version
Thanks for your help, Jouni. That seems to have fixed the problem.