Group Abstract Group Abstract

Message Boards Message Boards

0
|
2.9K Views
|
2 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Assigning colors to individual points in ListPlot

Posted 2 years ago
POSTED BY: Kerry Litvin
2 Replies
Posted 2 years ago

One way, using Style and Which:

pts = Range[-5, 5];
color[n_] := Which[n < 0, Red, n > 0, Green, True, Black]

ListPlot[Table[Style[pts[[i]], color[pts[[i]]]], {i, Length[pts]}]]
POSTED BY: Hans Milton
Posted 2 years ago

Use Select to extract each category of points and then overlay plots of the two categories using Show. You can do that with any number of properties, selections and colors.

yourlist={{-1,3},{2,4},{-2,2},{3,1}};
Show[
  ListPlot[Select[yourlist,#[[1]]<0&],PlotStyle->Red],
  ListPlot[Select[yourlist,#[[1]]>0&],PlotStyle->Green],
  AxesOrigin->{0,0},PlotRange->All
]
POSTED BY: Bill Nelson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard