Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Graphical Representation of Lists

Say I have three lists: a={1,5,10,15} b={2,4,6,8} and c={1,1,0,1,0}. I want a plot which has a as the x axis, b as the y axis and a red/black dot to mark 1/0. For. e.g. The coordinate (5,4) will have a red dot.
In other words the coordinate (a[i],b[i]) will have a red/black dot depending on whether c[i] is 1 or 0.
I have been trying my hand with ListPlot but can't figure out the options.

like image 990
skr Avatar asked Mar 03 '11 14:03

skr


1 Answers

I suggest this.

a = {1, 5, 10, 15};
b = {2, 4, 6, 8};
c = {1, 1, 0, 1};

Graphics[
  {#, Point@{##2}} & @@@ 
    Thread@{c /. {1 -> Red, 0 -> Black}, a, b},
  Axes -> True, AxesOrigin -> 0
]

Mathematica graphics

Or shorter but more obfuscated

Graphics[
  {Hue[1, 1, #], Point@{##2}} & @@@ Thread@{c, a, b}, 
  Axes -> True, AxesOrigin -> 0
]
like image 173
Mr.Wizard Avatar answered Oct 21 '22 11:10

Mr.Wizard