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


Groups > comp.soft-sys.math.mathematica > #4178 > unrolled thread

Re: Using colored text in PlotLabel

Started byRobert Rosenbaum <robertr@math.uh.edu>
First post2011-08-03 23:56 +0000
Last post2011-08-06 06:12 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  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

#4178 — Re: Using colored text in PlotLabel

FromRobert Rosenbaum <robertr@math.uh.edu>
Date2011-08-03 23:56 +0000
SubjectRe: Using colored text in PlotLabel
Message-ID<j1cn72$glt$1@smc.vnet.net>
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.  
For some reason, <> doesn't seem to work on Styled strings.



On Aug 3, 2011, at 6:06 AM, Andrew DeYoung wrote:

> Hi,
>
> I often use Mathematica 7 to display data, using ListPlot.  Since I
> end up creating plots containing lots of colored lines, it would be
> helpful if I could color the text that I display above my plots using
> PlotLabel.  Do you know if there is a way to do this without having to
> resort to the Plot Legends Package, which I sometimes find somewhat
> cumbersome to use (because I often end up having to spend a lot of
> time positioning the legend so that it does not cover my plot lines)?
>
> If you have time, I have plotted an example plot of mine here:
> http://www.andrew.cmu.edu/user/adeyoung/august2/august2.jpg
>
> In that plot, I have created the title using PlotLabel.  Specifically,
> I used the following Mathematica commands:
>
> ListPlot[
> {{energies1eq[[1]], fp*energies1eq[[7]]}\[Transpose], {20 +
> energies1md[[1]], fp*energies1md[[7]]}\[Transpose],
> {energies2eq[[1]], fp*energies2eq[[7]]}\[Transpose], {20 +
> energies2md[[1]], fp*energies2md[[7]]}\[Transpose],
> {energies3eq[[1]], fp*energies3eq[[7]]}\[Transpose], {20 +
> energies3md[[1]], fp*energies3md[[7]]}\[Transpose]},
> PlotRange->All,Joined->True,AxesLabel->{"t (ps)","(kcal/
> mol)"},PlotLabel->"Total Energy\nRed: Velocity-Verlet\nGreen: Leapfrog
> \nBlue: Accurate Velocity-Verlet\n",PlotStyle-
>> {Pink,Red,Green,Darker[Green],Cyan,Blue},ImageSize->imgSize]
>
> Do you know how to make my title that says, for example, "Red: ",
> actually red?
>
> Thank you very much for your time!
>
> Andrew DeYoung
> Carnegie Mellon University
>


Best,
Robert





[toc] | [next] | [standalone]


#4185

FromA Retey <awnl@gmx-topmail.de>
Date2011-08-06 06:12 +0000
Message-ID<j1ilvt$clm$1@smc.vnet.net>
In reply to#4178
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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web