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: [mg120715] Re: Using colored text in PlotLabel
  • From: Heike Gramberg <heike.gramberg at gmail.com>
  • Date: Sun, 7 Aug 2011 06:14:41 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201108060613.CAA13031@smc.vnet.net>

You can also use Column and get rid of the \n's:

ListPlot[RandomReal[1, {50}], PlotRange -> All, Joined -> True,
 AxesLabel -> {"t (ps)", "(kcal/mol)"},
 PlotLabel ->
  Column[{"Total Energy", Style["Red: Velocity-Verlet", Red],
    Style["Green:Leapfrog", Green],
    Style["Blue: Accurate Velocity-Verlet", Blue]}, Center],
 PlotStyle -> {Pink, Red, Green, Darker[Green], Cyan, Blue},
 ImageSize -> 400]

You can automatically print the labels in the PlotStyle colours by doing 
something like

colours = {Pink, Red, Green, Darker[Green], Cyan, Blue};
labels = {"Label 1", "Label 2", "Label 3", "Label 4"};

ListPlot[RandomReal[{0, 1}, {4, 50}] + Range[4], PlotRange -> All,
 Joined -> True, AxesLabel -> {"t (ps)", "(kcal/mol)"}, PlotLabel ->
  Column[Prepend[
    MapThread[
     Style, {labels, PadRight[colours, Length[labels], colours]}],
    "Plot Title"], Center],
 PlotStyle -> colours, ImageSize -> 400]

Heike

On 6 Aug 2011, at 08:13, Chris Degnen wrote:

> You can use Row to join styled strings:
>
> ListPlot[{Table[Random[], {50}]},
>  PlotRange -> All, Joined -> True, AxesLabel -> {"t (ps)", "(kcal/mol)"},
>  PlotLabel -> Row[{"Total Energy\n",
>      Style["Red: Velocity-Verlet\n", Red],
>      Style[ "Green:Leapfrog\n", Green],
>      Style["Blue: Accurate Velocity-Verlet\n", Blue]}],
>  PlotStyle -> {Pink, Red, Green, Darker[Green], Cyan, Blue},
>  ImageSize -> 400]
>
>
> Robert Rosenbaum wrote:
>>
>> 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
>>
>>
>>
>>
>>
>>
>
>





  • Prev by Date: Re: TransformedDistribution, distribution of a mean
  • Next by Date: Re: Strange behaviour of NMinimize when doing curve fitting
  • Previous by thread: Re: Using colored text in PlotLabel
  • Next by thread: Simple Doppler effect