# representing triplet data set with color on 2d plot [duplicate]

I have a huge list of data in the form of triplets numbers (e.g. {x,y,z}) and I want 2d plot. In which I want to plot y vs x on which values of z should be shown with color depending on the value of z for each x,y point. Means variation of z with color on x,y plot. Is it possible to show plot legend outside the plot boundaries?

## marked as duplicate by Sjoerd C. de Vries, m_goldberg, Jens, Artes, halirutan♦Jul 3 '13 at 23:13

• Some suggestions: ListDensityPlot, ListPlot, Graphics/Point – Kuba Jul 3 '13 at 12:44

The Simplest way is to use Graphics and put the points.

dat = Table[{x, Sin[x], Cos[x]}, {x, 0., 4 \[Pi], \[Pi]/10.}]; (*trial data set*)
(*column 1 and 2 is for data and 3 is for colour*)

ndata = Length[dat];
min = Min[dat[[All, 3]]];max = Max[dat[[All, 3]]];
col = (dat[[All, 3]] - min)/(max - min);
(*to scale the colour index between 0 and 1*)

Graphics[Table[{ColorData["NeonColors"][col[[i]]], PointSize -> Large,
Point[{dat[[i, 1]], dat[[i, 2]]}]}, {i, 1, ndata}], Axes -> True, AspectRatio -> .5]


## Simplified Version [courtesy Anon and belisarius]

col = Rescale[dat[[All, 3]]]; pts = dat[[All, 1 ;; 2]];
Graphics[Table[{ColorData["NeonColors"][col[[i]]], PointSize -> Large,
Point[pts[[i]]]}, {i, ndata}], Axes -> True, AspectRatio -> .5]


## For drawing with Line

Graphics[Table[{ColorData["NeonColors"][col[[i]]], Thick,
Line[{pts[[i]], pts[[i + 1]]}]}, {i, ndata - 1}], Axes -> True, AspectRatio -> .5]


## Using ColorScheme as legend

Needs["PlotLegends"]
(*create legendbox*)
legend = Graphics[Legend[ColorData["NeonColors"][1 - #1] &, 10, " Max", " Min",
LegendShadow -> None, LegendBorder -> Automatic]];

(*put it in inset*)
lps = {11.0, .5}; (*legend position*)
Graphics[{Table[{ColorData["NeonColors"][col[[i]]], Thick,
Line[{pts[[i]], pts[[i + 1]]}]}, {i, ndata - 1}],
Inset[legend, lps, Automatic, {1, 1}]},
Axes -> True, AspectRatio -> .5, ImageSize -> 500]


• Take a look at Rescale[] – Dr. belisarius Jul 3 '13 at 18:29
• I was just about to say that, (1) col = Rescale[dat[[All, 3]]];, (2) pts = dat[[All, 1 ;; 2]]; simplifies the Point to Point[pts[[i]]] and (3) {i, 1, ndata} is equivalent to {i,ndata}. But nice answer, +1. – C. E. Jul 3 '13 at 18:32
• Thanks for suggestions but if i want join all my points then how can i include this in your given code – physicist Jul 4 '13 at 19:10
• well @physicist, then you can chose two points at a time and use Line`. – Sumit Jul 4 '13 at 20:55
• How can i reverse the order of colors in this scheme in the code – physicist Jul 11 '13 at 7:57