Thank you very much.
I know very little about numpy in fact.

If I don't find a pure matplotlib method, I will use your suggestion with wx.
I think however matplotlib may be used only (and it will be even better as I plan to make a Qt version in the future)

So, in :
>>> from matplotlib.transforms import Value
>>> from matplotlib.backends.backend_agg import RendererAgg
>>> r = RendererAgg(50, 50, Value(72))
>>> r.draw_image (0, 0, im)

What is the correct format for im ?



On 7/2/07, Christopher Barker <> wrote:
I don't know how to do it with the MPL agg back-end, but I think you
mentioned wx, and you can do it there instead. a wxImage can be
constructed from a buffer object, then saved as a PNG. You may need to
set the rgb and alpha portions separately. See the wxPython wiki and
search for "Image".


>             matrix = []
>             buffer = self.get_renderer().tostring_argb()
>             l, h = self.GetSize()
>             for ligne in xrange(h):
>                 matrix.append([])
>                 for colonne in xrange(l):
>                     i = 4*(ligne*h + colonne)
>                     pixel = buffer[i:i+4]
>                     matrix[-1].append(pixel)

This is a very slow way to create the numpy array!

Option a: first create an empty array:

matrix = numpy.empty((l,h,4), numpy.byte)

then fill that in. but even better:

you can build the array directly from the buffer string:

matrix = numpy.fromstring(buffer, dtype=numpy.byte)

Christopher Barker, Ph.D.

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception