How do you add contrasting text to color image

I have I have an image with both light and dark regions. I want to write text on
it in a color that contrasts with the underlying image color.

Right now if I make the text black, it is not very legible if the underling
color is dark. Similarly, if I make the text white, it is not legible if the
underlying color is light. (using gray text will not work)

One way to solve the problem would be to:
-produce the image
  e.g. im1=plt.imshow (zM,origin='lower',interpolation='hanning',extent=None)
-get the underlying color from the image where I want to place the text
  Need help here. How do I get the color from im1
-calculate a contrasting color
  Need help here
-plot the text in the contrasting color

Another way would be to use a font with a dark edge and light interior (or vice
versa) but I know of know such font for matplotlib.

Any help appreciated...

You could put your text inside a colored box - see e.g.
http://matplotlib.sourceforge.net/users/text_intro.html

-Jeff

···
-- Jeffrey S. Whitaker Phone : (303)497-6313
Meteorologist FAX : (303)497-6449
NOAA/OAR/PSD R/PSD1 Email : 325 Broadway Office : Skaggs Research Cntr 1D-113
Boulder, CO, USA 80303-3328 Web :

Jeffrey.S.Whitaker@…259…http://tinyurl.com/5telg

FYI, the svn version of matplotlib supports this.

http://matplotlib.sourceforge.net/trunk-docs/examples/pylab_examples/patheffect_demo.html

Regards,

-JJ

···

On Tue, Mar 16, 2010 at 12:10 PM, PaterMaximus <patermaximus@...2016...> wrote:

Another way would be to use a font with a dark edge and light interior (or vice
versa) but I know of know such font for matplotlib.