|
From: Mark B. <ma...@gm...> - 2007-01-03 21:06:21
|
Hello -
I want to set the backgroundcolor of text with the set_backgroundcolor
function.
Does that actually work?
I saw a more complicated way to do it by defining a bbox, but this would be
much easier (if I got it to work).
Here's my example that doesn't work.
Thanks for any suggestions,
Mark
from pylab import *
plot([1,2,3])
t = text(1,2,'Hello')
t.set_backgroundcolor('r')
draw()
|
|
From: John H. <jdh...@ac...> - 2007-01-03 21:16:06
|
>>>>> "Mark" == Mark Bakker <ma...@gm...> writes:
Mark> Hello - I want to set the backgroundcolor of text with the
Mark> set_backgroundcolor function. Does that actually work? I
Mark> saw a more complicated way to do it by defining a bbox, but
Mark> this would be much easier (if I got it to work). Here's my
Mark> example that doesn't work. Thanks for any suggestions,
Strange. When I saw your post my first thought was "hmmm, I didn't
know we had a text background color". I looked through the text.py
code and it is there as a property, but is totally unused. I don't
know who added it, but apparently someone got interrupted mid-code.
That someone could be me, but if anyone knows where this came from
speak up; otherwise it will be removed.
The bbox is the standard way to do this, and is a bit more general
since you can set the alpha, the linewidth, the edgecolor, etc...
ax.text(1,2,'hi mom', bbox=dict(facecolor='red'))
JDH
|
|
From: Mark B. <ma...@gm...> - 2007-01-03 21:56:41
|
Thanks John. This works great. I think, however, that set_backgroundcolor would be useful. It should be easy to fix. If nobody speaks up, I will take a crack at it, Mark On 1/3/07, John Hunter <jdh...@ac...> wrote: > > >>>>> "Mark" == Mark Bakker <ma...@gm...> writes: > > Mark> Hello - I want to set the backgroundcolor of text with the > Mark> set_backgroundcolor function. Does that actually work? I > Mark> saw a more complicated way to do it by defining a bbox, but > Mark> this would be much easier (if I got it to work). Here's my > Mark> example that doesn't work. Thanks for any suggestions, > > Strange. When I saw your post my first thought was "hmmm, I didn't > know we had a text background color". I looked through the text.py > code and it is there as a property, but is totally unused. I don't > know who added it, but apparently someone got interrupted mid-code. > That someone could be me, but if anyone knows where this came from > speak up; otherwise it will be removed. > > The bbox is the standard way to do this, and is a bit more general > since you can set the alpha, the linewidth, the edgecolor, etc... > > ax.text(1,2,'hi mom', bbox=dict(facecolor='red')) > > JDH > |
|
From: John H. <jdh...@ac...> - 2007-01-03 22:06:23
|
>>>>> "Mark" == Mark Bakker <ma...@gm...> writes:
Mark> Thanks John. This works great. I think, however, that
Mark> set_backgroundcolor would be useful. It should be easy to
Mark> fix. If nobody speaks up, I will take a crack at it, Mark
What do you have in mind, a simple convenience function that does
def set_backgroundcolor(self, color):
"""
Set the background color of the text by updating the bbox facecolor
ACCEPTS: any matplotlib color
"""
if self._bbox is None:
self._bbox = dict(facecolor=color, edgecolor=color)
else:
self._bbox.update(dict(facecolor=color))
I'm not too opposed to it, but it does violate the maxim "There should be one--
and preferably only one --obvious way to do it." Of course, we
violate this throughout mpl offerings lots of convenience functions,
but it is something to bear in mind.
|
|
From: Mark B. <ma...@gm...> - 2007-01-03 22:12:21
|
Thanks for writing the convenience function John ! I think there is a large group (like the students in my class) who use matplotlib as a simple tool to make beautiful graphs. To compete with matlab we need to keep simple tasks simple. I personally think that this convenience function is a good one to add. Probably under pylab. Anybody else want to weigh in? Mark On 1/3/07, John Hunter <jdh...@ac...> wrote: > > >>>>> "Mark" == Mark Bakker <ma...@gm...> writes: > > Mark> Thanks John. This works great. I think, however, that > Mark> set_backgroundcolor would be useful. It should be easy to > Mark> fix. If nobody speaks up, I will take a crack at it, Mark > > What do you have in mind, a simple convenience function that does > > def set_backgroundcolor(self, color): > """ > Set the background color of the text by updating the bbox > facecolor > > ACCEPTS: any matplotlib color > """ > if self._bbox is None: > self._bbox = dict(facecolor=color, edgecolor=color) > else: > self._bbox.update(dict(facecolor=color)) > > I'm not too opposed to it, but it does violate the maxim "There should be > one-- > and preferably only one --obvious way to do it." Of course, we > violate this throughout mpl offerings lots of convenience functions, > but it is something to bear in mind. > |