Sorry, my bad. I always hit reply without checking... it is not the
first time did that,
Here is the solution for the list sake:
""" trim image """
import StringIO, Image
imgdata = StringIO.StringIO()
fig.savefig(imgdata, dpi=300, format='png')
im = Image.open(imgdata)
def trim(im, border):
from PIL import ImageChops
bg = Image.new(im.mode, im.size, border)
diff = ImageChops.difference(im, bg)
bbox = diff.getbbox()
# found no content
raise ValueError("cannot trim; image was empty")
im = trim(im,'white')
The StringIO trick is a copy-and-paste from the matplotlib faq. And the
trim function I got from here:
Thanks for the discussion, I learned a lot abouth the Agg backend.
BTW: What I meant by limitation is the fact that Agg has no GUI like the
nice QT window I was using before. The users of this script have no
experience with scripting languages and enjoyed choosing the format and
filename using a GUI interface.
In addition, PIL's show() use an external linux program "xv". In the end
I wanted to eliminate one external linux program (Imagemagik convert)
but ended up with another one...
On 04/06/2010 05:01 PM, Friedrich Romstedt wrote:
2010/4/5 Filipe Fernandes <ocefpaf@...287...>:
Thanks a lot. In the end the "StringIO-solution" worked fine. The only
limitation is that this works only for the Agg backend.
I'm happy to hear this. As far as I know, using the Agg backend is
not a limitation, because it provides fully anti-aliased output.
Besides being available on all platforms (?).
Let me make a small hint: The matplotlib-users mailing list is
configured that by default replies go to the sender only, not to
matplotlib-users, so maybe you want to let the list know about your
Anyway I'm happy for your Thanks,
so thanks too,