Group Abstract Group Abstract

Message Boards Message Boards

0
|
7K Views
|
3 Replies
|
1 Total Like
View groups...
Share
Share this post:

[?] Color coding scatterplots?

Posted 6 years ago

Given a list A and a ListPlot of A how can the plotting points be color coded by the values in list B?

A={{1,1},{2,2},{3,3},{4,4},{5,5}};
B={Red,Red,Blue,Blue,Blue};

This has to be an easy task than I am making difficult. Help please.

POSTED BY: Dave Lubbers
3 Replies

You could wrap the point data values in Style, something along the lines of:

ListPlot[{Style[{1,1},Red], Style[{2,2},Blue],etc..}]

This is described in the documentation for ListPlot if you drill down into Scope and then Wrappers.

POSTED BY: Ian Williams
POSTED BY: Dave Lubbers

This will do the trick.

A = RandomReal[{0, 10}, {10000, 2}];
B = RandomChoice[{Red, Green, Blue}, 10000];

AB = GatherBy[Thread[{A, B}], Last];

col = AB[[All, 1, 2]];
points = AB[[All, All, 1]];

ListPlot[points, PlotStyle -> col]

enter image description here

POSTED BY: Martijn Froeling
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard