-
-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
I've been using matplotlib to overlay text on charts, and I've run into an interesting problem. I've been trying to overlay multiple lines of translucent colored text onto a chart, with each line being a different color, with the color being set by the content of the text. I intend to draw several lines of text inside of a translucent box that lies over the chart space. It appears that matplotlib doesn't allow you to individually set each line of text to a different color within an ax.text() box -- when a color parameter is specified on a plot.figtext() command, it changes all of the lines inside of the box to be the same color, rather than only changing the color of that particular line. It appears that matplotlib doesn't allow me to draw several lines of differently colored text within the same box; matplotlib ends up forcing each line of text to be the same color as the issuance of any text colorization command seems to apply to all lines of text.
To draw lines of translucent text in boxes where each line of text is a unique color, I can draw a textbox around each individual line of text. Although this method will allow me to effect different colors for each line of translucent text, the output doesn't look very good.
To obtain the desired result I have been drawing colored lines of text directly on the chart using figtext(), and after doing that, l'd superimpose a blank text box over the existing lines of text using ax.text(), and assign an alpha value to the box parameters that makes the box transparent. This would render the box, and all of the text that it overlays, transparent with the same alpha value.
This worked fine when I started doing it in Fedora 18. I've just upgraded to F20 and now my code doesn't work -- the translucency and box-drawing function is broken. I've traced down the problem. In older versions of matplotlib, it was possible to draw a box by populating the text parameter of the ax.text() function with blank lines of text ( lines of text comprised of blank spaces plus linefeeds). With the newest version of matplotlib, if ax.text() is passed blank lines of text containing linefeeds, the function responds by interpreting the text content to be null, and instead of drawing a suitably large box, it draws a box that is of zero size. It seems as if the text is being disregarded when the text is comprised of blank spaces and linefeed characters.
Is there any way to cause ax.text() to draw a properly sized box by feeding it a text string that is composed of space characters and linefeeds? If possible, I'd like to revert to the old behavior, and I'm not quite sure whether this new behavior is a new feature or a bug. Thanks.