MathGroup Archive 2011

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

Search the Archive

Re: Using colored text in PlotLabel

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120704] Re: Using colored text in PlotLabel
  • From: A Retey <awnl at gmx-topmail.de>
  • Date: Sat, 6 Aug 2011 02:11:39 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201108031106.HAA10819@smc.vnet.net> <j1cn72$glt$1@smc.vnet.net>

Hi,

> This does the trick:
>
> Plot[x^2, {x, -2, 2},
>   PlotLabel ->  Style["Hello", Blue] Style["\nHello", Red]]
>
> although I'm sure that there's a better way to combine the two strings.

Written as such, this is a multiplication, which might behave very 
different from what you want (considering ordering, line breaks etc.). 
Since at least version 6 you can use arbitrary expressions as 
PlotLabels. To combine various parts you can use an appropriate 
combination of Row, Column and Grid:

Plot[x^2, {x, -2, 2},
  PlotLabel -> Column[{Style["Blue", Blue], Style["Red", Red]}]]

You could also do something like this:

Plot[{x, x^2}, {x, -2, 2}, PlotLabel -> Grid[{
     {Graphics[{Red, Line[{{0, 0}, {1, 0}}]}, ImageSize -> {20, 20}],
      "linear"},
      {Graphics[{Blue, Line[{{0, 0}, {1, 0}}]}, ImageSize -> {20, 20}],
       "quadratic"}
     }, Alignment -> {Left, Center}, Spacings -> 0],
  PlotStyle -> {Red, Blue}]

> For some reason,<>  doesn't seem to work on Styled strings.

Style["hello",Blue] is not a styled string, it is an expression with 
head Style that the FrontEnd in StandardForm shows as blue text, see e.g.:

Style["test", Blue] // FullForm

Once that is clear, it's not such a big surprise that StringJoin doesn't 
like joining those expressions...

hth,

albert




  • Prev by Date: more problems with TransformedDistribution
  • Next by Date: Re: In Version 8, Combinatorial&GraphTheory functions
  • Previous by thread: Re: Using colored text in PlotLabel
  • Next by thread: Re: Using colored text in PlotLabel