Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

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


Math Forum » Discussions » Software » comp.soft-sys.math.mathematica

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

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Bob Hanlon

Posts: 906
Registered: 10/29/11
Re: ListPlot - assigning a list of colors to a set of points
Posted: Nov 6, 2013 12:27 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


There is no need to use Table with RandomChoice. Use

cols = RandomChoice[{Red, Green, Blue}, nbr]



Bob Hanlon


On Tue, Nov 5, 2013 at 12:12 PM, Gordon Robertson <grobertson@bcgsc.ca>wrote:

> Thanks Bob,
>
> Your solutions are compact. The code below extends your first example to
> use a long list of XY coordinates and colours in ListPlot.
>
> nbr = 1000
> xy = Transpose[{RandomReal[{0, 1}, nbr], RandomReal[{0, 1}, nbr]}]; (* xy
> data to plot *)
> cols = Table[RandomChoice[{Red, Green, Blue}], {i, nbr}]; (* list of
> colors *)
>
> ListPlot[List /@ xy, PlotStyle -> (Directive[PointSize[0.02],
> Opacity[0.6], #] & /@ cols)]
>
> Gordon
>
>
> On 2013-11-05, at 8:34 AM, Bob Hanlon wrote:
>
> Make each point a separate data list and repeat the PointSize:
>
> ListPlot[List /@ {{1, 1}, {2, 2}, {3, 3}},
> PlotStyle -> (Directive[PointSize[0.02], #] & /@
> {Red, Green, Blue})]
>
> Although you can use a List instead of Directive:
>
> ListPlot[List /@ {{1, 1}, {2, 2}, {3, 3}},
> PlotStyle -> ({PointSize[0.02], #} & /@
> {Red, Green, Blue})]
>
> Alternatively,
>
> ListPlot[List /@ {{1, 1}, {2, 2}, {3, 3}},
> PlotStyle -> {Red, Green, Blue},
> PlotMarkers -> {Automatic, Medium}]
>
>
> Bob Hanlon
>
>
> On Mon, Nov 4, 2013 at 11:16 PM, Gordon Robertson <grobertson@bcgsc.ca>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}]]
>>
>> 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
>> Vancouver BC Canada
>> www.bcgsc.ca<http://www.bcgsc.ca>
>>

>
>
>




Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.