Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Getting Color *names* as strings?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67480] Re: Getting Color *names* as strings?
  • From: albert <awnl at arcor.de>
  • Date: Wed, 28 Jun 2006 03:51:16 -0400 (EDT)
  • References: <e7qmpk$6ne$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

AES wrote:

> Trying out different named Colors in a plot by using
> 
>    greens={CinnabarGreen, ChromeOxideGreen, CobaltGreen, etc};
> 
>    Do[ Plot[ func, range, PlotStyle -> greens[[k]],
>                     PlotLabel -> ToString[greens[[k]]] ] ,
>          {k, 1, Length[greens]} ];
> 
> Works fine -- except the PlotLabel comes out as "RGB[num, num, num]" --
> and using SymbolName[greens[[1]]] or even SymbolName[CinnabarGreen] does
> _not_ give the string "CinnabarGreen".
> 
> How can I get the *name* of each color as a string to put in PlotLabel
> or in a Text label?
> 
> (Trivial problem, I agree, but just frustrating enough to be interesting)

it is not so trivial, since you have to intercept the evaluation chain at an
early stage. This gets the string you are looking for:

SymbolName[Unevaluated[CinnabarGreen]]

unfortunatly, even your list greens will contain the evaluated colors, you
can check this with:

OwnValues[greens]

so there is no way to find the names from the list greens (expect by
searching and comparing with all available colors...). There are basically
two things you can do to achieve what you want:

1) use strings in the list greens and ToExpression in the PlotStyles option:

greens = {"CinnabarGreen","ChromeOxideGreen",...}
Plot[func,range,PlotStyle->ToExpression[greens[[k]]],PlotLabel->greens[[k]]]

2) make sure the symbols are held from the beginning and evaluate only when
needed, e.g.:

greens = Hold[CinnabarGreen, ChromeOxideGreen, CobaltGreen, etc]

Plot[func,range,
     PlotStyle->greens[[k]],
     PlotLabel->Extract[greens,k,Function[{x},SymbolName[Unevaluated[x]],HoldAll]]
]

hm, maybe the extract can be done more simply, but it obviously takes quite
some effort to prevent mathematica from evaluating symbols with ownvalues
so the approach to use strings in the list might be much easier to
handle... Note also that it is easier to get a list of strings for the
available colors than a list of (unevaluated) symbols:

greens = Names["Graphics`Colors`*Green*"]

gives you a list of various greens as strings... I also remember there was a
package announced in this group which shows all named colors in a table.
maybe search the archive or mathsource for it...

hth

albert


  • Prev by Date: Re: Solving an equation
  • Next by Date: Re: solving an equation with sums
  • Previous by thread: Re: Getting Color *names* as strings?
  • Next by thread: Viewing animations also on RealTime3D