2010/3/28 Filipe Pires Alvarenga Fernandes <[email protected]>:
> Hello list
> I've trying for a while a "python only" solution to remove white spaces that
> Basemap generate to keep the aspect ratio. I found these two threads that
> explain the issue better:
I think maybe you can make use of the Agg Backend to achieve a
Python-only solution to obtain a PIL Image from a figure without
bypassing over the HDD:
Furthemore, if this doesn't work, maybe you can use a StringIO as
"file", then seek() the StringIO and reread with PIL from the
"file-like" StringIO, or something like that?
#
# Render the Figure to a PIL Image ...
#
# Prepare figure to be of pixel extent *shape* ...
dpi = figure.dpi
figure.set_size_inches(float(shape[0]) / dpi, float(shape[1]) / dpi)
# Create the rendering Canvas ...
#
# We also convert the picture to an RGB string.
canvas = matplotlib.backends.backend_agg.FigureCanvasAgg(figure)
canvas.draw()
image_string = canvas.tostring_rgb()
# Create a PIL Image from RGB string ...
image = Image.fromstring("RGB", shape, image_string)
# Now do whatever you want with the Image.
Friedrich
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
Matplotlib-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/matplotlib-users