Message Boards Message Boards


[✓] Color coding scatterplots?

Posted 1 month ago
3 Replies
1 Total Likes

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


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

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.

Tried the wrappers. Worked great for small datasets. For large (500,000) datasets it was too slow. Had to go ahead and separate the data into multiple lists. The language R was the model.

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

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract