sending plot output to a bitmap widget

An associated question is how one easily maps a

    > monochromatic image that is displayed in matplotlib back
    > into a monochromatic array. Normally it's going to be
    > converted to rgba even if rgba is not really needed. Is
    > there any simple way of mapping it back to intensity
    > (histogram of the rgba values to determine if such a
    > mapping exists?). Hmmm.

Well, assuming you passed it to matplotlib with no colormap, then a
default intensity grayscale would be used. In that case, just build
the rgb array as above using string methods and then take the r, g, or
b slice out of it since they are all identical.

If you passed in a colormap, you would need to invert the colormap,
which would be relatively easy to provide in the colors.Colormap
interface but I'm having trouble imagining why someone would want to
do this.

Both of these would be lossy, of course, eg if you started with an
array of floats you would get back an array of UInt8s.

Note agg comes with several helpful pixel converters functions: gray8,
rgb565, rgb555, bgr24, bgr24, bgra32, abgr32, argb32, rgba32. Perhaps
the best general solution is to define these as module constants and
provide a single tostring method that takes one of these constants and
returns the appropriate string representation. I can image that this
would be useful both for backend agg and the image module.

JDH

John Hunter wrote:

Well, assuming you passed it to matplotlib with no colormap, then a
default intensity grayscale would be used. In that case, just build
the rgb array as above using string methods and then take the r, g, or
b slice out of it since they are all identical.

Yep, this is the simple case.

If you passed in a colormap, you would need to invert the colormap,
which would be relatively easy to provide in the colors.Colormap
interface but I'm having trouble imagining why someone would want to
do this.

Me too. (Well, I'm thinking of older displays that actually
used color lookup tables. The image would be stored in the
display buffer as 8-bit intensity, and displayed to the screen
through a lookup color table. In that case one could manipulate
the image display as a intensity image and expect to read it
out as such while using whatever psychedelic color table one wanted
to please their eyes. But that's rare these days.)

Both of these would be lossy, of course, eg if you started with an
array of floats you would get back an array of UInt8s.

Yep.

Note agg comes with several helpful pixel converters functions: gray8,
rgb565, rgb555, bgr24, bgr24, bgra32, abgr32, argb32, rgba32. Perhaps
the best general solution is to define these as module constants and
provide a single tostring method that takes one of these constants and
returns the appropriate string representation. I can image that this
would be useful both for backend agg and the image module.

Sounds reasonable.

Perry