MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Applying Apply

  • To: mathgroup at smc.vnet.net
  • Subject: [mg107801] Re: [mg107782] Applying Apply
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Fri, 26 Feb 2010 04:07:52 -0500 (EST)
  • Reply-to: hanlonr at cox.net

plabel = {
   Text["Orange", {10, 44}],
   Text["Blue", {10, 50}, {1, 1}],
   Text["Green", {2, 99}],
   Text["Red", {2, 20}]};

textColours = {Orange, Blue, Green, Red};

First method

Graphics[Style @@@ Thread[{plabel, textColours}]]

Second method

Graphics[Thread[{plabel, textColours}] /.
  {Text[str_String, r__], clr_} -> 
     Text[Style[str, clr], r]]


Bob Hanlon

---- Chris Degnen <degnen at cwgsy.net> wrote: 

=============
Can anyone suggest an elegant way to apply a function - in this case a
Style - to elements in a list.
In the example below I'm applying colours to their names.  (I don't
know how Text is being used so I aimed to preserve the original
structure).  As you can see it took me two lines to splice in the
colour styles.  I thought I should have been able to do it in one, but
couldn't figure out how.

plabel = {Text["Orange", {10, 44}], Text["Blue", {10, 50}],
   Text["Green", {2, 99}], Text["Red", {2, 20}]};
textColours = {Orange, Blue, Green, Red};
plabel2 =
  Append[Transpose[Apply[{#1, #2} &, plabel, 1]], textColours];
plabel = Apply[Text[Style[#1, #3], #2] &, Transpose[plabel2], 1]




  • Prev by Date: Re: Applying Apply
  • Next by Date: Re: square roots in Q[r]
  • Previous by thread: Re: Applying Apply
  • Next by thread: Stock tracking