MathGroup Archive 1993

[Date Index] [Thread Index] [Author Index]

Search the Archive

re: Scatter plot

  • To: mathgroup at yoda.physics.unc.edu
  • Subject: re: Scatter plot
  • From: tgayley (Todd Gayley)
  • Date: Fri, 26 Mar 1993 08:46:45 -0600

Dennis Schaeffer (schaeffer_dennis at macmail1.rtsg.mot.com) asks:

>I would like to know if there is a way to plot a list of {x, y, z} values on a
>2D scatter plot where x and y determine position on the x-y plane and the z
>value would determine the color for the dot. 
>
>Thanks in advance,
>
>-Dennis-

This can be done very easily with a replacement rule. You have a list of
triples and you want to turn each triple into a "Point of the first two
numbers and a Hue of the third". That verbal statement translates directly
into a single line of code.

In[1]:=  data = Table[Random[],{8},{3}]

Out[1]= {{0.376687, 0.528899, 0.145955}, {0.288695, 0.32407, 0.784966}, 
         {0.334509, 0.35705, 0.740198}, {0.175488, 0.03863, 0.730385}, 
         {0.665578, 0.927367, 0.329819}, {0.669595, 0.464939, 0.374672}, 
         {0.774491, 0.790915, 0.562525}, {0.963257, 0.92481, 0.450602}}

In[2]:=  data2 = data /. {x_,y_,z_} :> {Hue[z],Point[{x,y}]}

Out[2]= {{Hue[0.145955], Point[{0.376687, 0.528899}]}, 
         {Hue[0.784966], Point[{0.288695, 0.32407}]}, 
         {Hue[0.740198], Point[{0.334509, 0.35705}]}, 
         {Hue[0.730385], Point[{0.175488, 0.03863}]}, 
         {Hue[0.329819], Point[{0.665578, 0.927367}]}, 
         {Hue[0.374672], Point[{0.669595, 0.464939}]}, 
         {Hue[0.562525], Point[{0.774491, 0.790915}]}, 
         {Hue[0.450602], Point[{0.963257, 0.92481}]}}

Of course, you could use any color primitive in place of Hue, but note that
it must come before the Point if it is to have any effect.

In[3]:=  Show[Graphics[data2, Axes->True]]


--Todd Gayley






  • Prev by Date: Developers Conference
  • Next by Date: Re: mathlink
  • Previous by thread: Developers Conference
  • Next by thread: ParametricPlot3D and NeXT