Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4185

Re: Using colored text in PlotLabel

From A Retey <awnl@gmx-topmail.de>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Using colored text in PlotLabel
Date 2011-08-06 06:12 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <j1ilvt$clm$1@smc.vnet.net> (permalink)
References <201108031106.HAA10819@smc.vnet.net> <j1cn72$glt$1@smc.vnet.net>

Show all headers | View raw


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

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Re: Using colored text in PlotLabel Robert Rosenbaum <robertr@math.uh.edu> - 2011-08-03 23:56 +0000
  Re: Using colored text in PlotLabel A Retey <awnl@gmx-topmail.de> - 2011-08-06 06:12 +0000

csiph-web