Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: ListPlot - assigning a list of colors to a set of
Replies: 6   Last Post: Nov 6, 2013 12:29 AM

 Messages: [ Previous | Next ]
 Gordon Robertson Posts: 18 Registered: 11/15/07
Re: ListPlot - assigning a list of colors to a set of
Posted: Nov 6, 2013 12:28 AM

Thank you, Itai.
G

On 2013-11-04, at 9:08 PM, Itai Seggev wrote:

On Mon, Nov 04, 2013 at 11:16:19PM -0500, Gordon Robertson wrote:

I'm using Mathematica v9.x on a Mac, with OS X 10.7.5.

Could I ask about something that likely has a very simple solution? I have a list of XY coordinates for say 500 points that will become a scatterplot via ListPlot. I need to assign a colour to each point, using a list of labels (histology, risk, =85).

I've generated ArrayPlot graphics for cases like this for some time. For example, given some labels in column 4 of a 'hist' table:
colours = Table[{
Switch[name = hist[[i, 4]],
"Classical", Green, "Tall cell", Red, "Other", Blue]
}, {i, Length[hist]}];
ArrayPlot[{colours}, AspectRatio -> 0.1, Frame -> False]

For a ListPlot, I'd have thought that something as simple as dropping a list of colours into a PlotStyle Directive would do the job. But the following line plots three blue points, rather than a Red, Green and Blue point.
ListPlot[{{1, 1}, {2, 2}, {3, 3}},
PlotStyle -> Directive[PointSize[0.02], {Red, Green, Blue}]]

You have two issues. The first is that you misunderstand Directive. A
Directive represent a single style, both semantically and practically. It can
never represent a group styles.

The second is that ListPlot assigns colors on a per dataset basis, not per
point. So assuming you wish to repeat cyclically and each point needs its own
color, you can do something like

ListPlot[List /@ {{1, 1}, {2, 2}, {3, 3}},
PlotStyle -> {Directive[PointSize[0.02`], RGBColor[1, 0, 0]],
Directive[PointSize[0.02`], RGBColor[0, 1, 0]],
Directive[PointSize[0.02`], RGBColor[0, 0, 1]]}]

Is there a simple way to declare a list of colours in ListPlot? I've looked through the PlotStyle documentation, and apologize if I've missed seeing how to do this.

Thanks very much for your help.

Gordon
--
Gordon Robertson
Michael Smith Genome Sciences Centre
BC Cancer Agency
www.bcgsc.ca<http://www.bcgsc.ca><http://www.bcgsc.ca>
--
Itai Seggev
Mathematica Algorithms R&D
217-398-0700

Date Subject Author
11/6/13 Gordon Robertson
11/6/13 Bob Hanlon
11/6/13 Gordon Robertson
11/6/13 Gordon Robertson
11/6/13 Bob Hanlon
11/6/13 Tomas Garza Hernandez